Concurrify
Turn non-concurrent FantasyLand 3 Applicatives concurrent.
Most time-dependent applicatives are very useful as Monads, because it gives
them the ability to run sequentially, where each step depends on the previous.
However, they lose the ability to run concurrently. This library allows one to
wrap a Monad
(with sequential ap
) in an
Alternative
(with parallel ap
).
Usage
const concurrify = require('concurrify');
const Future = require('fluture');
const zero = Future(() => {});
const alt = Future.race;
const ap = (mx, mf) => Future.both(mx, mf).map(([x, f]) => f(x));
const ConcurrentFuture = concurrify(Future, zero, alt, ap);
ConcurrentFuture(Future.of(1)).sequential.fork(console.error, console.log);
API
concurrify :: (Applicative f, Alternative (m f))
=> (TypeRep f, f a, (f a, f a) -> f a, (f a, f (a -> b)) -> f b)
-> f c
-> m f c
Interoperability