Sweet.js operator macros for common operations
f >>= g; // chaining
a <*> b <*> c; // ap
a +++ b +++ c; // concat
a |> f; g <| a; // piping
f ->> g; f <<- g; // function composition
$ npm install macros.operators
You can either choose to use all macros, by compiling with the root module:
sjs --module macros.operators yourfile.sjs
Or choose only the appropriate macros by including each one separately:
sjs --module macros.operators/macros/applicative \
--module macros.operators/macros/functor \
yourfile.sjs
a <|> b
: Alternative (a.orElse(=> b)
);
a <*> b
: Applicative (a.ap(b)
);a <**> b
: Right-associative applicative (b.ap(a)
);
a |> f
: Forward piping (f(a)
);f <| a
: Backward piping (f(a)
);f ->> g
: Forward function composition (x => f(g(x))
);g <<- f
: Backward function composition (x => f(g(x))
);a @f b, c, ...
: Infix application (f(a, b, c, ...)
);
a <$> f
: Map (a.map(f)
);
a >>= f
: Chain (a.chain(f)
);f =<< a
: Backward chain (a.chain(f)
);f >=> g
: Chain composition (x => f(x).chain(g)
);g <=< f
: Backward chain composition (x => f(x).chain(g)
);
a +++ b
: Concatenation (a.concat(b)
);
a::b
: Prototype shorthand (a.prototype.b
);
Copyright (c) 2014 Quildreen Motta.
Released under the MIT licence.