async-functional
The asynchronous generator AsyncGenerator
appears on many occasions. For example, fetching a set of records from a REST API, or dealing with database records. This package tries to give a functional flavor to dealing with such situations.
One can consider AysncGenerator
as a stream. This library allows async generators to be treated in functional manner.
New JSON Path transformer added as functors so that it is possible to process set of JSONPaths together to create a single object.
Contents
Functional Operators
Inspired by rxjs
and functional programming, this package gives operators such as map
, filter
, zip
, take
or takeWhile
alongwith folds such as foldl
. Hopefully, this allows programs to be implemented using simple for
loop.
TODO - Controlled Parallalism
While working with multiple such async generators, this package will try to create a controlled parallalism.
Documentation
Prelude - A set of generic functions
Convert an Iterable into an async generator
; ; // Now you can iterate using for..await..of for await of input console.log"Output: " + i;
Collect the result of async generator into a promise
; ; // Convert it back into a promise ;
Functors and folds - Higher order functions
Functors and other higher order functions to process async generator.
Create a functor - Lift a function to process async generator
; // Create a async generator from an array ; // A simple function to square the numbers ; // Use functor to lift square to squareMap ; // Use map to square each element for await of squareMapinput
Use map as a functor
; // Create a async generator from an array; // Use map to square each elementfor await of mapx * x, input
Use filter to selectively iterate over elements
; // Create a async generator from an array; // Filter to remove odd elements // Use map to square each elementfor await of filterevenFilter, input // Output =>// output = 2// output = 4
JSON Path transformation
; ; ; ; ; ; // Should see { mynumber: 101.0, myboolean: false }