Primitives

basic_utils.primitives.natural_nums(start=0, end=None)[source]

Yields a lazy sequence of natural numbers

>>> from itertools import islice
>>> list(islice(natural_nums(5), 3))
[5, 6, 7]
Return type:Iterator[int]
basic_utils.primitives.identity(x)[source]

Returns the same values passed as arguments

>>> x = (10, 20)
>>> identity(x)
(10, 20)
Return type:Any
basic_utils.primitives.comp(*funcs)[source]

Takes a set of functions and returns a fn that is the composition of those functions

Return type:Callable
basic_utils.primitives.complement(fn)[source]

Takes a function fn and returns a function that takes the same arguments as fn with the opposite truth value.

>>> not_five = complement(lambda x: x == 5)
>>> not_five(6)
True
Return type:Callable
basic_utils.primitives.inc(n)[source]

Increments n by 1

>>> inc(10)
11
Return type:int
basic_utils.primitives.dec(n)[source]

Decrements n by 1

>>> dec(5)
4
Return type:int
basic_utils.primitives.even(n)[source]

Returns true if n is even

>>> even(2)
True
Return type:bool
basic_utils.primitives.odd(n)[source]

Returns true if n is odd

>>> even(3)
False
Return type:bool
basic_utils.primitives.compose(*funcs)

Takes a set of functions and returns a fn that is the composition of those functions

Return type:Callable