functionalscript
Advanced tools
Comparing version 0.0.127 to 0.0.128
@@ -98,2 +98,31 @@ "use strict"; | ||
/** | ||
* @template I | ||
* @typedef {{ | ||
* readonly i: <O>(f: (input: I) => O) => Chain<O> | ||
* readonly result: () => I | ||
* }} Chain | ||
*/ | ||
/** @type {<I>(value: I) => Chain<I>} */ | ||
const chain = value => ({ | ||
i: f => chain(f(value)), | ||
result: () => value | ||
}) | ||
/** | ||
* @template I | ||
* @template T | ||
* @typedef {{ | ||
* readonly x: <O>(f: (v: T) => O) => Pipe<I, O> | ||
* readonly f: (input: I) => T | ||
* }} Pipe | ||
*/ | ||
/** @type {<I, T>(f: (input: I) => T) => Pipe<I, T>} */ | ||
const pipex = f => ({ | ||
x: g => pipex(pipe(f)(g)), | ||
f, | ||
}) | ||
module.exports = { | ||
@@ -128,6 +157,8 @@ | ||
pipex, | ||
/** @type {Reduce<number, number>} */ | ||
sum: { merge: a => i => a + i, init: 0 }, | ||
/** @type {<I, X>(_: (_: I) => X) => <O>(_: Reduce<X, O>) => Reduce<I, O>} */ | ||
/** @type {<I, X>(f: (init: I) => X) => <O>(reduce: Reduce<X, O>) => Reduce<I, O>} */ | ||
map: f => ({merge, init}) => ({ | ||
@@ -134,0 +165,0 @@ merge: pipe(merge)(pipe(f)), |
{ | ||
"name": "functionalscript", | ||
"version": "0.0.127", | ||
"version": "0.0.128", | ||
"description": "FunctionalScript is a functional subset of JavaScript", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
57571
746