How to use the cytoolz.curry function in cytoolz

To help you get started, we’ve selected a few cytoolz examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ethereum / trinity / eth / vm / forks / byzantium / __init__.py View on Github external
@curry
def get_uncle_reward(block_reward: int, block_number: int, uncle: BaseBlock) -> int:
    block_number_delta = block_number - uncle.block_number
    validate_lte(block_number_delta, MAX_UNCLE_DEPTH)
    return (8 - block_number_delta) * block_reward // 8
github ethereum / trinity / eth / vm / forks / byzantium / headers.py View on Github external
@curry
def compute_difficulty(
        bomb_delay: int,
        parent_header: BlockHeader,
        timestamp: int) -> int:
    """
    https://github.com/ethereum/EIPs/issues/100
    """
    parent_timestamp = parent_header.timestamp
    validate_gt(timestamp, parent_timestamp, title="Header.timestamp")

    parent_difficulty = parent_header.difficulty
    offset = parent_difficulty // DIFFICULTY_ADJUSTMENT_DENOMINATOR

    has_uncles = parent_header.uncles_hash != EMPTY_UNCLE_HASH
    adj_factor = max(
        (
github ethereum / eth-utils / tests / curried-utils / test_curried.py View on Github external
def curry_namespace(ns):
        return dict(
            (name, curry(f) if should_curry(f) else f)
            for name, f in ns.items()
            if "__" not in name
        )
github sbg / Mitty / mitty / analysis / bamfilters.py View on Github external
@cytoolz.curry
def alignment_hist(dmv_mat, riter):
  """Compute the dmv matrix which is as defined as follows:

  A 3D matrix with dimensions:
    Xd - alignment error  [0]  -max_d, ... 0, ... +max_d, wrong_chrom, unmapped (2 * max_d + 1 + 2)
    MQ - mapping quality  [1]  0, ... max_MQ (max_MQ + 1)
    vlen - length of variant carried by read [2]  -max_vlen, ... 0, ... +max_vlen, Ref, Margin, Multiple
                                                  (2 * max_vlen + 1 + 2)



  * The ends of the ranges (-max_d, max_d) (-max_vlen, +max_vlen) include that value and all values exceeding
  * Ref collects all the reference reads
  * Margin collects the marginal sums for d x MQ. This is necessary because one read can appear in multiple
    bins on the vlen axis and cause a slight excess of counts when marginals are computed
github eriknw / cytoolz / cytoolz / curried.py View on Github external
map = cytoolz.curry(map, numargs=2)
mapcat = cytoolz.curry(mapcat, numargs=2)
memoize = cytoolz.curry(memoize, numargs=1)
merge_sorted = cytoolz.curry(merge_sorted, numargs=1)
merge_with = cytoolz.curry(merge_with, numargs=2)
nth = cytoolz.curry(nth, numargs=2)
partition = cytoolz.curry(partition, numargs=2)
partition_all = cytoolz.curry(partition_all, numargs=2)
partitionby = cytoolz.curry(partitionby, numargs=2)
pluck = cytoolz.curry(pluck, numargs=2)
reduce = cytoolz.curry(reduce, numargs=2)
reduceby = cytoolz.curry(reduceby, numargs=3)
remove = cytoolz.curry(remove, numargs=2)
sliding_window = cytoolz.curry(sliding_window, numargs=2)
sorted = cytoolz.curry(sorted, numargs=1)
take = cytoolz.curry(take, numargs=2)
take_nth = cytoolz.curry(take_nth, numargs=2)
unique = cytoolz.curry(unique, numargs=1)
update_in = cytoolz.curry(update_in, numargs=3)
valfilter = cytoolz.curry(valfilter, numargs=2)
valmap = cytoolz.curry(valmap, numargs=2)
github ethereum / trinity / eth / tools / fixtures / generation.py View on Github external
@curry
def generate_fixture_tests(metafunc: Any,
                           base_fixture_path: str,
                           filter_fn: Callable[..., Any]=identity,
                           preprocess_fn: Callable[..., Any]=identity) -> None:
    """
    Helper function for use with `pytest_generate_tests` which will use the
    pytest caching facilities to reduce the load time for fixture tests.

    - `metafunc` is the parameter from `pytest_generate_tests`
    - `base_fixture_path` is the base path that fixture files will be collected from.
    - `filter_fn` handles ignoring or marking the various fixtures.  See `filter_fixtures`.
    - `preprocess_fn` handles any preprocessing that should be done on the raw
       fixtures (such as expanding the statetest fixtures to be multiple tests for
       each fork.
    """
    fixture_namespace = os.path.basename(base_fixture_path)
github eriknw / cytoolz / cytoolz / curried.py View on Github external
accumulate = cytoolz.curry(accumulate, numargs=2)
assoc = cytoolz.curry(assoc, numargs=3)
cons = cytoolz.curry(cons, numargs=2)
countby = cytoolz.curry(countby, numargs=2)
do = cytoolz.curry(do, numargs=2)
drop = cytoolz.curry(drop, numargs=2)
filter = cytoolz.curry(filter, numargs=2)
get = cytoolz.curry(get, numargs=2)
get_in = cytoolz.curry(get_in, numargs=2)
groupby = cytoolz.curry(groupby, numargs=2)
interleave = cytoolz.curry(interleave, numargs=1)
interpose = cytoolz.curry(interpose, numargs=2)
iterate = cytoolz.curry(iterate, numargs=2)
join = cytoolz.curry(join, numargs=4)
keyfilter = cytoolz.curry(keyfilter, numargs=2)
keymap = cytoolz.curry(keymap, numargs=2)
map = cytoolz.curry(map, numargs=2)
mapcat = cytoolz.curry(mapcat, numargs=2)
memoize = cytoolz.curry(memoize, numargs=1)
merge_sorted = cytoolz.curry(merge_sorted, numargs=1)
merge_with = cytoolz.curry(merge_with, numargs=2)
nth = cytoolz.curry(nth, numargs=2)
partition = cytoolz.curry(partition, numargs=2)
partition_all = cytoolz.curry(partition_all, numargs=2)
partitionby = cytoolz.curry(partitionby, numargs=2)
pluck = cytoolz.curry(pluck, numargs=2)
reduce = cytoolz.curry(reduce, numargs=2)
reduceby = cytoolz.curry(reduceby, numargs=3)
remove = cytoolz.curry(remove, numargs=2)
sliding_window = cytoolz.curry(sliding_window, numargs=2)
sorted = cytoolz.curry(sorted, numargs=1)
take = cytoolz.curry(take, numargs=2)
github thautwarm / Rem / remlang / compiler / order_dual_opt.py View on Github external
'and': curry(lambda x, y: x and y),

    '|': curry(operator.or_),
    'or': curry(lambda a, b: a or b),

    '%': curry(operator.mod),
    '**': curry(operator.pow),
    '>>': curry(operator.lshift),
    '<<': curry(operator.rshift),
    '||': curry(operator.or_),
    '^': curry(operator.xor),
    '<': curry(operator.lt),
    '<=': curry(operator.le),
    '>': curry(operator.gt),
    '>=': curry(operator.ge),
    '==': curry(operator.eq),
    'is': curry(operator.is_),
    '!=': curry(operator.ne),
    'in': curry(lambda e, collection: e in collection),

}


def order_dual_opt(seq):
    if len(seq) is 3:
        return BinExp(*seq)

    linked_list = RevLinkedList.from_iter(seq)
    arg_indices = argsort([op_priority[e] for e in seq if isinstance(e, str)])
    arg_indices.reverse()

    indices = [idx for idx, e in enumerate(seq) if isinstance(e, str)]
github eriknw / cytoolz / cytoolz / curried.py View on Github external
# import toolz
# import toolz.curried
#
# for key, val in sorted(toolz.curried.__dict__.items()):
#     if isinstance(val, toolz.functoolz.Curry):
#         print '%s = cytoolz.curry(%s, numargs=%s)' % (key, key, val._numargs)

accumulate = cytoolz.curry(accumulate, numargs=2)
assoc = cytoolz.curry(assoc, numargs=3)
cons = cytoolz.curry(cons, numargs=2)
countby = cytoolz.curry(countby, numargs=2)
do = cytoolz.curry(do, numargs=2)
drop = cytoolz.curry(drop, numargs=2)
filter = cytoolz.curry(filter, numargs=2)
get = cytoolz.curry(get, numargs=2)
get_in = cytoolz.curry(get_in, numargs=2)
groupby = cytoolz.curry(groupby, numargs=2)
interleave = cytoolz.curry(interleave, numargs=1)
interpose = cytoolz.curry(interpose, numargs=2)
iterate = cytoolz.curry(iterate, numargs=2)
join = cytoolz.curry(join, numargs=4)
keyfilter = cytoolz.curry(keyfilter, numargs=2)
keymap = cytoolz.curry(keymap, numargs=2)
map = cytoolz.curry(map, numargs=2)
mapcat = cytoolz.curry(mapcat, numargs=2)
memoize = cytoolz.curry(memoize, numargs=1)
merge_sorted = cytoolz.curry(merge_sorted, numargs=1)
merge_with = cytoolz.curry(merge_with, numargs=2)
nth = cytoolz.curry(nth, numargs=2)
partition = cytoolz.curry(partition, numargs=2)
partition_all = cytoolz.curry(partition_all, numargs=2)
partitionby = cytoolz.curry(partitionby, numargs=2)
github thautwarm / Rem / remlang / compiler / order_dual_opt.py View on Github external
'*': curry(operator.mul),
    '/': curry(operator.truediv),
    '//': curry(operator.floordiv),
    '++': curry(lambda x, y: itertools.chain(x, y)),
    '--': curry(lambda x, y: [_ for _ in x if _ not in y]),

    '&': curry(operator.and_),
    'and': curry(lambda x, y: x and y),

    '|': curry(operator.or_),
    'or': curry(lambda a, b: a or b),

    '%': curry(operator.mod),
    '**': curry(operator.pow),
    '>>': curry(operator.lshift),
    '<<': curry(operator.rshift),
    '||': curry(operator.or_),
    '^': curry(operator.xor),
    '<': curry(operator.lt),
    '<=': curry(operator.le),
    '>': curry(operator.gt),
    '>=': curry(operator.ge),
    '==': curry(operator.eq),
    'is': curry(operator.is_),
    '!=': curry(operator.ne),
    'in': curry(lambda e, collection: e in collection),

}


def order_dual_opt(seq):
    if len(seq) is 3: