delphi.utils package
Submodules
delphi.utils.fp module
Helper functions for functional programming.
- prepend(x: delphi.utils.fp.T, xs: Iterable[delphi.utils.fp.T]) Iterator[delphi.utils.fp.T] [source]
Prepend a value to an iterable.
- Parameters:
x – An element of type T.
xs – An iterable of elements of type T.
- Returns:
Iterator – An iterator that yields x followed by elements of xs.
Examples
>>> from delphi.utils.fp import prepend >>> list(prepend(1, [2, 3])) [1, 2, 3]
- append(x: delphi.utils.fp.T, xs: Iterable[delphi.utils.fp.T]) Iterator[delphi.utils.fp.T] [source]
Append a value to an iterable.
- Parameters:
x – An element of type T.
xs – An iterable of elements of type T.
- Returns:
Iterator – An iterator that yields elements of xs, then yields x.
Examples
>>> from delphi.utils.fp import append >>> list(append(1, [2, 3])) [2, 3, 1]
- scanl(f: Callable[[delphi.utils.fp.T, delphi.utils.fp.U], delphi.utils.fp.T], x: delphi.utils.fp.T, xs: Iterable[delphi.utils.fp.U]) Iterator[delphi.utils.fp.T] [source]
Make an iterator that returns accumulated results of a binary function applied to elements of an iterable.
\[scanl(f, x_0, [x_1, x_2, ...]) = [x_0, f(x_0, x_1), f(f(x_0, x_1), x_2), ...]\]- Parameters:
f – A binary function of two arguments of type T.
x – An initializer element of type T.
xs – An iterable of elements of type T.
- Returns:
Iterator – The iterator of accumulated results.
Examples
>>> from delphi.utils.fp import scanl >>> list(scanl(lambda x, y: x + y, 10, range(5))) [10, 10, 11, 13, 16, 20]
- scanl1(f: Callable[[delphi.utils.fp.T, delphi.utils.fp.T], delphi.utils.fp.T], xs: Iterable[delphi.utils.fp.T]) Iterator[delphi.utils.fp.T] [source]
Make an iterator that returns accumulated results of a binary function applied to elements of an iterable.
\[scanl1(f, [x_0, x_1, x_2, ...]) = [x_0, f(x_0, x_1), f(f(x_0, x_1), x_2), ...]\]- Parameters:
f – A binary function of two arguments of type T.
xs – An iterable of elements of type T.
- Returns:
Iterator – The iterator of accumulated results.
Examples
>>> from delphi.utils.fp import scanl1 >>> list(scanl1(lambda x, y: x + y, range(5))) [0, 1, 3, 6, 10]
- foldl(f: Callable[[delphi.utils.fp.T, delphi.utils.fp.U], delphi.utils.fp.T], x: delphi.utils.fp.T, xs: Iterable[delphi.utils.fp.U]) delphi.utils.fp.T [source]
Returns the accumulated result of a binary function applied to elements of an iterable.
\[foldl(f, x_0, [x_1, x_2, x_3]) = f(f(f(f(x_0, x_1), x_2), x_3)\]Examples
>>> from delphi.utils.fp import foldl >>> foldl(lambda x, y: x + y, 10, range(5)) 20
- foldl1(f: Callable[[delphi.utils.fp.T, delphi.utils.fp.T], delphi.utils.fp.T], xs: Iterable[delphi.utils.fp.T]) delphi.utils.fp.T [source]
Returns the accumulated result of a binary function applied to elements of an iterable.
\[foldl1(f, [x_0, x_1, x_2, x_3]) = f(f(f(f(x_0, x_1), x_2), x_3)\]Examples
>>> from delphi.utils.fp import foldl1 >>> foldl1(lambda x, y: x + y, range(5)) 10
- iterate(f: Callable[[delphi.utils.fp.T], delphi.utils.fp.T], x: delphi.utils.fp.T) Iterator[delphi.utils.fp.T] [source]
Makes infinite iterator that returns the result of successive applications of a function to an element
\[iterate(f, x) = [x, f(x), f(f(x)), f(f(f(x))), ...]\]Examples
>>> from delphi.utils.fp import iterate, take >>> list(take(5, iterate(lambda x: x*2, 1))) [1, 2, 4, 8, 16]
- ptake(n: int, xs: Iterable[delphi.utils.fp.T]) Iterable[delphi.utils.fp.T] [source]
take with a tqdm progress bar.
- ltake(n: int, xs: Iterable[delphi.utils.fp.T]) List[delphi.utils.fp.T] [source]
A non-lazy version of take.
- compose(*fs: Any) Callable [source]
Compose functions from left to right.
e.g. compose(f, g)(x) = f(g(x))
- rcompose(*fs: Any) Callable [source]
Compose functions from right to left.
e.g. rcompose(f, g)(x) = g(f(x))
- flatMap(f: Callable, xs: Iterable) List [source]
Map a function onto an iterable and flatten the result.
- repeatfunc(func: Callable, *args)[source]
Repeat calls to func with specified arguments.
Example: repeatfunc(random.random)
delphi.utils.indra module
delphi.utils.misc module
delphi.utils.shell module
Helper functions for shell operations.
- cd(destination_directory)
delphi.utils.web module
Helper functions for web activity.