@masaeedu/infix
v1.2.1
Published
## Summary A simple trick for applying a bag of static functions where the data goes last as infix functions.
Downloads
23
Readme
Infix
Summary
A simple trick for applying a bag of static functions where the data goes last as infix functions.
Usage
const { infix, uncurry } = require("@masaeedu/infix");
const Int = {
"+": x => y => y + x,
"-": x => y => y - x,
"*": x => y => y * x,
"/": x => y => y / x
};
const result = infix(Int) (1) ["+"] (2) ["+"] (5) ["*"] (5) ["+"] (2) .unwrap;
// => 42Properties
The expression:
infix(F)(a)
.f(b)
.g(c).unwrapdesugars to:
F.g(c)(F.f(b)(a))Note that this only works when F.f, F.g etc. are binary functions with the data as the second argument.
Some functions may not fit this mould. Functions of arbitrary arity are supported using uncurrying. The expression:
infix(F)(a)
.f(b)
[uncurry](g)([c, d])
.h(e).unwrapdesugars to:
F.h(e)(
F.g(c)(d)(
F.f(b)(
a)))Disclaimer
Use of this library may result in you being instantly fired. I accept no responsibility.
