0.0.3 • Published 7 years ago

@lato/sec v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
7 years ago

@lato/sec

Few functions meant to be composed with each other in order to modify deeply nested structures:

  • _ix(n): value in Array at index n (no bounds checking)
  • _just: value in Maybe if it's not nothing
  • _left: value in Either if it's left
  • _right: value in Either if it's right
  • _result: result of a function
  • _argument: arguments to a function
  • _sum[prop]/_sum(prop): prop branch of a Sum type
  • _object[prop]/_object(prop): value at prop 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);
0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago