Sequence traversing functions
|
Returns the first item in an iterable or |
|
Returns an iterator of all but the first element in the iterable. |
|
same as |
|
Returns the second item in iterable, or |
|
Returns the third item in iterable, or |
|
Returns the fourth item in iterable, or |
|
Returns the fifth item in iterable, or |
|
returns the last element in the iterable. |
|
returns an iterable of all but the last element in the iterable |
|
Returns the first n number of elements in iterable. |
|
Returns All the Elements after the first n number of elements in iterable. |
|
Constructs a iterable list by taking elements from |
|
Drops elements from |
|
Equivalent to |
|
Returns appropriate iterator for the given iterable. |
|
Returns appropriate reversed iterator for the given iterable. |
|
counts the number of elements in the iterable, works with map objects, filter objets, and iterators. |
|
returns a tuple of the number of elements in the iterable and the iterable itself. |
- functionali.first(iterable: Iterable[Any]) Optional[Any]
Returns the first item in an iterable or
None
if iterable is empty. If iterable is a dict, returns a tuple of the First key-value pair>>> first([1,2,3,4,5]) 1 >>> first({1:"a", 2:"b"}) (1, "a")
Added in version: 0.1.0
- functionali.rest(iterable: Iterable) Iterator
Returns an iterator of all but the first element in the iterable. If iterable is empty it returns an empty iterator.
>>> list(rest([1,2,3,4,5])) [2, 3, 4, 5]
>>> tuple(rest({1:"a", 2:"b", 3:"c"})) ((2,"b"), (3, "c"))
>>> tuple(rest([])) ()
Added in version: 0.1.0
- functionali.ffirst(iterable: Iterable[Any]) Optional[Any]
same as
first(first(iterable))
expects a nested iterable, returns None if iterable is empty>>> ffirst([[1,2], [3,4], [5,6]]) 1
Added in version: 0.1.0
- functionali.second(iterable: Iterable[Any]) Optional[Any]
Returns the second item in iterable, or
None
if length is less than 2>>> second([1,2,3,4,5]) 2
Added in version: 0.1.0
- functionali.third(iterable: Iterable[Any]) Optional[Any]
Returns the third item in iterable, or
None
if length is less than 3>>> third([1,2,3,4,5]) 3
Added in version: 0.1.0
- functionali.fourth(iterable: Iterable[Any]) Optional[Any]
Returns the fourth item in iterable, or
None
if length is less than 4>>> fourth([1,2,3,4,5]) 4
Added in version: 0.1.0
- functionali.fifth(iterable: Iterable[Any]) Optional[Any]
Returns the fifth item in iterable, or
None
if length is less than 5>>> fifth([1,2,3,4,5]) 5
Added in version: 0.1.0
- functionali.last(iterable: Iterable[Any]) Optional[Any]
returns the last element in the iterable.
>>> last([1,2,3,4]) 4 >>> last({1: 'a', 2: 'b', 3: 'c'}) (3, "c")
Added in version: 0.1.0
- functionali.butlast(iterable: Iterable[Any]) Optional[Tuple[Any]]
returns an iterable of all but the last element in the iterable
>>> butlast([1, 2, 3]) (1, 2)
Added in version: 0.1.0
- functionali.take(n: int, iterable: Iterable) Tuple
Returns the first n number of elements in iterable. Returns an empty tuple if iterable is empty
>>> take(3, [1,2,3,4,5]) (1, 2, 3) >>> take(2, {1: "a", 2: "b", 3: "c"}) ((1, "a"), (2, "b"))
Added in version: 0.1.0
- functionali.drop(n: int, iterable: Iterable) Tuple
Returns All the Elements after the first n number of elements in iterable. Returns an empty tuple if iterable is empty
>>> drop(3, [1,2,3,4,5]) (4,5) >>> drop(2, {1: "a", 2: "b", 3: "c"}) ((3, "c"),)
Added in version: 0.1.0
- functionali.take_while(predicate: Callable, iterable: Iterable) Tuple
Constructs a iterable list by taking elements from
iterable
whilepredicate
is true, Stop taking after the first element falsifies the predicate.>>> take_while(is_even, [2,4,6,7,8,9,10]) (2,4,6) # Notice that it does not include 8 and 10
>>> def is_even_dict(d): #checks if the key of dict d is even return d[0]%2==0 >>> take_while(is_even_dict, {2:"a", 4:"b",5:"c"}) ((2, "a"), (4, "b"))
Added in version: 0.1.0
- functionali.drop_while(predicate: Callable, iterable: Iterable) Tuple
Drops elements from
iterable
whilepredicate
is true, And returns a tuple of the remaining elements initerable
.>>> drop_while(is_even, [2,4,6,7,8,9,10]) (7,8,9, 10)
>>> def is_even_dict(d): #checks if the key of dict d is even return d[0]%2==0 >>> drop_while(is_even_dict, {2:"a", 4:"b",5:"c"}) ((5, "c"),)
Added in version: 0.1.0
- functionali.split_with(predicate: Callable, iterable: Iterable) Tuple[Tuple, Tuple]
Equivalent to
(take_while(predicate, iterable), drop_while(predicate, iterable))
>>> split_with(is_even, [2, 4, 6, 7, 8, 9, 10]) ((2, 4, 6), (7, 8, 9, 10))
Added in version: 0.1.0
- functionali.iter_(iterable: Iterable) Iterator
Returns appropriate iterator for the given iterable. This is mainly created because python’s
iter
returns an iterable of keys instead of keys and values fordict
.>>> tuple(iter_({1: "a", 2: "b", 3: "c"})) ((1, "a"),(2, "b"), (3, "c"))
Added in version: 0.1.0
- functionali.reversed_(iterable: Iterable) Iterator
Returns appropriate reversed iterator for the given iterable. This is mainly created because python’s
reversed
returns an iterable of keys instead of keys and values fordict
.>>> tuple(reversed_({1: "a", 2: "b", 3: "c"})) ((3, 'c'), (2, 'b'), (1, 'a'))
Added in version: 0.1.0
- functionali.count(iterable: Iterable) int
counts the number of elements in the iterable, works with map objects, filter objets, and iterators.
count
will consume iterators, usecount_
if you want access to the iterators. Added in version: 0.1.2>>> count(iter([1,2,3])) 3
- functionali.count_(iterable: Iterable) Tuple[int, Iterable]
returns a tuple of the number of elements in the iterable and the iterable itself. This can be used if you wish to find the length of iterators and want to consume the iterators later on. Added in version: 0.1.2 >>> count(iter([1,2,3])) (3,[1,2,3])