@visisoft/staticland
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -168,2 +168,3 @@ 'use strict'; | ||
// fromNilable :: (a|undefined|null) -> Maybe a | ||
fromNilable = semmelRamda.ifElse(semmelRamda.isNil, nothing, of$1), | ||
@@ -194,4 +195,11 @@ | ||
//join = mx => isJust(mx) ? mx.flat() : singleNothing, // TODO: alt mx.flat() | ||
join$1 = mx => mx.flat(), | ||
//join = mx => isJust(mx) ? mx.flat() : singleNothing, // alternative: mx.flat() | ||
join$1 = mx => | ||
isJust(mx) | ||
? (isJust(mx[0]) | ||
? mx[0] | ||
: isNothing(mx[0]) ? nothing() : mx // this else case makes the implementation different from chain(identity) | ||
) | ||
: nothing(), | ||
//map = curry((f, mx) => isJust(mx) ? mx.map(unary(f)) : singleNothing), // alt mx.map(unary(f)) | ||
@@ -201,4 +209,6 @@ // map :: (a -> b) -> Maybe a -> Maybe b | ||
// chain :: (a -> Maybe b) -> Maybe a -> Maybe b | ||
//chain = curry((f, mx) => isJust(mx) ? mx.flatMap(f) : singleNothing), // alt mx.flatMap(unary(f)) | ||
chain$1 = semmelRamda.curry((f, mx) => mx.flatMap(semmelRamda.unary(f))), | ||
//chain = curry((f, mx) => isJust(mx) ? mx.flatMap(f) : singleNothing), | ||
//chain = curry((f, mx) => mx.flatMap(unary(f))), | ||
chain$1 = semmelRamda.curry((f, mx) => isJust(mx) ? f(mx[0]) : nothing()), | ||
ap$1 = semmelRamda.curry((mf, mx) => chain$1(f => map$1(f, mx), mf)), | ||
@@ -371,3 +381,7 @@ reduce = semmelRamda.reduce,//curry((f, initial, mx) => mx.reduce(f, initial)), | ||
// maybeToPromise :: e -> Maybe a -> Promise e a | ||
maybeToPromise = semmelRamda.curry((e, ma) => maybe(semmelRamda.thunkify(reject)(e), of, ma)); | ||
maybeToPromise = semmelRamda.curry((e, ma) => maybe(semmelRamda.thunkify(reject)(e), of, ma)), | ||
// maybeToObj :: key -> Maybe a -> ({}|{key: a}) | ||
// key = String | ||
maybeToObj = semmelRamda.curry((keyName, ma) => maybe(semmelRamda.always({}), semmelRamda.objOf(keyName), ma)); | ||
@@ -377,3 +391,4 @@ var transformations = /*#__PURE__*/Object.freeze({ | ||
eitherToPromise: eitherToPromise, | ||
maybeToPromise: maybeToPromise | ||
maybeToPromise: maybeToPromise, | ||
maybeToObj: maybeToObj | ||
}); | ||
@@ -380,0 +395,0 @@ |
@@ -50,2 +50,3 @@ { | ||
"build:cjs": "rollup ./index.js --file dist/cjs/staticland.js --format cjs --external semmel-ramda", | ||
"prepare": "npm run build:cjs", | ||
"setup:chai": "rollup --input node_modules/chai/chai.js --file test/helpers/chai.mjs -c scripts/rollup.cjs-dependencies.config.js", | ||
@@ -57,3 +58,3 @@ "setup:hirestime": "rollup --input node_modules/hirestime/dist/index.js --file test/helpers/hirestime.mjs -c scripts/rollup.cjs-dependencies.config.js", | ||
"type": "module", | ||
"version": "0.1.2" | ||
"version": "0.1.3" | ||
} |
@@ -5,3 +5,3 @@ [![Dependencies](https://img.shields.io/david/semmel/StaticLand.svg?style=flat-square)](https://david-dm.org/semmel/StaticLand) [![NPM Version](https://img.shields.io/npm/v/@visisoft/staticland.svg?style=flat-square)](https://www.npmjs.com/package/@visisoft/staticland) | ||
==================== | ||
Operations on Algebraic Data Types (ADT) (Either, Maybe, Promise) realised with *free static functions*. The static functions do not expect custom-made ADTs but work on *native JavaScript types* as `Array` and `Promise`. | ||
Operations on Algebraic Data Types (ADT) (Either, Maybe, Promise) realised with *free static functions*. The static functions do not expect custom-made ADTs but work on the *native JavaScript types* as `Array` and `Promise`. Using these native types means that *@visisoft/staticland* practically gives up on type inspection and leaves that to the calling code. This is in line with the characteristics of JavaScript. | ||
@@ -8,0 +8,0 @@ Hello @visisoft/staticland |
@@ -9,3 +9,4 @@ /** | ||
/** | ||
* @typedef {Array} Maybe | ||
* @template T | ||
* @typedef {Array<T>} Maybe<T> | ||
*/ | ||
@@ -54,4 +55,11 @@ | ||
//join = mx => isJust(mx) ? mx.flat() : singleNothing, // TODO: alt mx.flat() | ||
join = mx => mx.flat(), | ||
//join = mx => isJust(mx) ? mx.flat() : singleNothing, // alternative: mx.flat() | ||
join = mx => | ||
isJust(mx) | ||
? (isJust(mx[0]) | ||
? mx[0] | ||
: isNothing(mx[0]) ? nothing() : mx // this else case makes the implementation different from chain(identity) | ||
) | ||
: nothing(), | ||
//map = curry((f, mx) => isJust(mx) ? mx.map(unary(f)) : singleNothing), // alt mx.map(unary(f)) | ||
@@ -61,4 +69,6 @@ // map :: (a -> b) -> Maybe a -> Maybe b | ||
// chain :: (a -> Maybe b) -> Maybe a -> Maybe b | ||
//chain = curry((f, mx) => isJust(mx) ? mx.flatMap(f) : singleNothing), // alt mx.flatMap(unary(f)) | ||
chain = curry((f, mx) => mx.flatMap(unary(f))), | ||
//chain = curry((f, mx) => isJust(mx) ? mx.flatMap(f) : singleNothing), | ||
//chain = curry((f, mx) => mx.flatMap(unary(f))), | ||
chain = curry((f, mx) => isJust(mx) ? f(mx[0]) : nothing()), | ||
ap = curry((mf, mx) => chain(f => map(f, mx), mf)), | ||
@@ -65,0 +75,0 @@ reduce = reduce_l,//curry((f, initial, mx) => mx.reduce(f, initial)), |
39303
11
632