chainlet - blocks for processing chains¶
chainlet library lets you quickly build iterative processing sequences.
At its heart, it is built for chaining generators/coroutines, but supports arbitrary objects.
It offers an easy, readable way to link elements using a concise mini language:
data_chain = read('data.txt') >> filterlet(preserve=bool) >> convert(apply=ast.literal_eval) for element in chain: print(element)
The same interface can be used to create chains that push data from the start downwards, or to pull from the end upwards.
push_chain = uppercase >> encode_r13 >> mark_of_insanity >> printer push_chain.send('uryyb jbeyq') # outputs 'Hello World!!!' pull_chain = word_maker >> cleanup >> encode_r13 >> lowercase print(next(pull_chain)) # outputs 'uryyb jbeyq'
Creating new elements is intuitive and simple, as
chainlet handles all the gluing and binding for you.
Most functionality can be created from regular functions, generators and coroutines:
@chainlet.genlet def moving_average(window_size=8): buffer = collections.deque([(yield)], maxlen=window_size) while True: new_value = yield(sum(buffer)/len(buffer)) buffer.append(new_value)
To just plug together existing chainlets, have a look at the Chainlet Mini Language. To port existing imperative code, the chainlet.protolink module provides simple helpers and equivalents of builtins.
Writing new chainlets is easily done writing generators, coroutines and functions, decorated with
chainlet.genlet() is best when state must be preserved between calls.
chainlet.funclet() allows resuming even after exceptions.
Advanced chainlets are best implemented as a subclass of
Overwrite instantiation and
chainlet_send() to change their behaviour .
In order to change binding semantics, overwrite the
Indices and tables¶
Documentation built from chainlet 1.3.1 at Feb 19, 2018.