0.0.3 • Published 7 years ago
@lato/sec v0.0.3
@lato/sec
Few functions meant to be composed with each other in order to modify deeply nested structures:
_ix(n)
: value inArray
at indexn
(no bounds checking)_just
: value inMaybe
if it's notnothing
_left
: value inEither
if it'sleft
_right
: value inEither
if it'sright
_result
: result of a function_argument
: arguments to a function_sum[prop]
/_sum(prop)
:prop
branch of aSum
type_object[prop]
/_object(prop)
: value atprop
property of an object
Mapping functions live in another repository.
const f = _object.baz << _object.quux << _mapMap << _just << _sum.blue << _mapArray;
f(x => x + 100)({
foo: 17,
bar: [1, 2, 3, 4],
baz: {
qux: "QUX",
quux: new Map([
["a", just(Sum.red({ x: 11, y: 12 }))],
["b", nothing],
["c", just(Sum.blue([20, 21, 22]))],
["d", just(Enum.green)],
["e", just(Sum.blue([-100, -99])]
])
}
});
// {
// foo: 17,
// bar: [1, 2, 3, 4],
// baz: {
// qux: "QUX",
// quux: new Map([
// ["a", just(Sum.red({ x: 11, y: 12}))],
// ["b", nothing],
// ["c", just(Sum.blue([120, 121, 122]))],
// ["d", just(Enum.green)],
// ["e", just(Sum.blue([0, 1]))]
// ])
// }
// }
Here, operator <<
is replaced with function composition using a
babel plugin.
Composition functions from other libraries would work the same way:
const f = g => _object.baz(_object.quux(_mapMap(_just(_sum.blue(_mapArray(g))))));
// ramda
const f = R.compose(_object.baz, _object.quux, _mapMap, _just, _sum.blue, _mapArray);
// lodash/fp
const f = fp.compose(_object.baz, _object.quux, _mapMap, _just, _sum.blue, _mapArray);