Collection of useful functions.

Basics

identity[source]

identity(x:T)

Indentity function.

simplify[source]

simplify(x)

Return an object of an iterable if it is lonely.

The simplify function is used to de-nest an iterable with a single element in it, as for instance [1], while leaving everything else constant. It can also exchange a function for its default argument.

simplify({1})
1
simplify(simplify)(lambda x='lul': 2*x)
'lullul'

listify[source]

listify(o=None, *rest, use_list=False, match=None)

Convert o to a list

What's very convenient is that it leaves lists invariant (it doen't nest them into a new list).

listify([1, 2])
[1, 2]
listify(1, 2, 3)
[1, 2, 3]

setify[source]

setify(o)

Turn any list like-object into a set.

setify(1, 2, 3)
{1, 2, 3}

tuplify[source]

tuplify(o, use_list=False, match=None)

Make o a tuple

tuplify(1)
(1,)

merge_tfms[source]

merge_tfms(*tfms)

Merge two dictionnaries by stacking common key into list.

merge_tfms(
    {'animals': ['cats', 'dog'], 'colors': 'blue'}, 
    {'animals': 'cats', 'colors': 'red', 'OS': 'i use arch btw'}
)
{'animals': ['cats', 'dog'], 'colors': ['red', 'blue'], 'OS': 'i use arch btw'}

compose[source]

compose(*funcs, order=None)

Create a function that composes all functions in funcs, passing along remaining *args and **kwargs to all

pipe[source]

pipe(*functions)

Pipe an arbitrary number of functions.

flow[source]

flow(data, *functions)

Flow data through a list of functions.

File manipulation helper

get_files[source]

get_files(path, extensions=None, recurse=False, folders=None, followlinks=True)

Get all those file names.

Path.decompress[source]

Path.decompress(dest='.')

Path.compress[source]

Path.compress(dest='.', keep_copy=True)

save_array[source]

save_array(array, fname, suffix)

Save an array with the given name and suffix.

def save_dataset(data):
    return 'NotImplementedError'