How to use the funcy.compat.range function in funcy

To help you get started, we’ve selected a few funcy 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 Suor / funcy / tests / test_seqs.py View on Github external
def test_lsplit():
    assert lsplit(_ % 2, range(5)) == ([1, 3], [0, 2, 4])
    # This behaviour moved to split_at()
    with pytest.raises(TypeError): lsplit(2, range(5))
github Suor / funcy / tests / test_seqs.py View on Github external
def test_pairwise():
    assert list(pairwise(range(3))) == [(0, 1), (1, 2)]
github Suor / funcy / tests / test_seqs.py View on Github external
def test_with_next():
    assert list(with_next(range(3))) == [(0, 1), (1, 2), (2, None)]
github Suor / funcy / tests / test_seqs.py View on Github external
def test_with_prev():
    assert list(with_prev(range(3))) == [(0, None), (1, 0), (2, 1)]
github Suor / funcy / tests / test_types.py View on Github external
def test_iterable():
    assert iterable([])
    assert iterable({})
    assert iterable('abc')
    assert iterable(iter([]))
    assert iterable(x for x in range(10))
    assert iterable(range(10))

    assert not iterable(1)
github Suor / funcy / tests / test_seqs.py View on Github external
def test_chunks():
    assert lchunks(2, [0, 1, 2, 3, 4]) == [[0, 1], [2, 3], [4]]
    assert lchunks(2, 1, [0, 1, 2, 3]) == [[0, 1], [1, 2], [2, 3], [3]]
    assert lchunks(3, 1, iter(range(3))) == [[0, 1, 2], [1, 2], [2]]
github Suor / funcy / tests / test_seqs.py View on Github external
def test_cat():
    assert lcat('abcd') == list('abcd')
    assert lcat(range(x) for x in range(3)) == [0, 0, 1]
github Suor / funcy / tests / test_seqs.py View on Github external
def test_ilen():
    assert ilen('xyz') == 3
    assert ilen(range(10)) == 10
github Suor / funcy / funcy / seqs.py View on Github external
def _cut(drop_tail, n, step, seq=EMPTY):
    if seq is EMPTY:
        step, seq = n, step
    # NOTE: range() is capable of slicing in python 3,
    if isinstance(seq, Sequence) and (PY3 or not isinstance(seq, range)):
        return _cut_seq(drop_tail, n, step, seq)
    else:
        return _cut_iter(drop_tail, n, step, seq)
github Suor / funcy / funcy / colls.py View on Github external
try:
        dest = next(it)
    except StopIteration:
        return None
    cls = dest.__class__

    if isinstance(dest, basestring):
        return ''.join(colls)
    elif isinstance(dest, Mapping):
        result = dest.copy()
        for d in it:
            result.update(d)
        return result
    elif isinstance(dest, Set):
        return dest.union(*it)
    elif isinstance(dest, (Iterator, range)):
        return chain.from_iterable(colls)
    elif isinstance(dest, Iterable):
        # NOTE: this could be reduce(concat, ...),
        #       more effective for low count
        return cls(chain.from_iterable(colls))
    else:
        raise TypeError("Don't know how to join %s" % cls.__name__)