@visisoft/staticland
Advanced tools
Comparing version 0.1.23 to 0.1.24
/* @license Apache-2.0 | ||
@visisoft/staticland v.0.1.23 visisoft.de | ||
(Build date: 10/4/2021 - 8:13:00 PM) | ||
@visisoft/staticland v.0.1.24 visisoft.de | ||
(Build date: 10/14/2021 - 3:36:52 PM) | ||
*/ | ||
@@ -5,0 +5,0 @@ 'use strict'; |
/* @license Apache-2.0 | ||
@visisoft/staticland v.0.1.23 visisoft.de | ||
(Build date: 10/4/2021 - 8:13:00 PM) | ||
@visisoft/staticland v.0.1.24 visisoft.de | ||
(Build date: 10/14/2021 - 3:36:52 PM) | ||
*/ | ||
@@ -5,0 +5,0 @@ 'use strict'; |
/* @license Apache-2.0 | ||
@visisoft/staticland v.0.1.23 visisoft.de | ||
(Build date: 10/4/2021 - 8:13:00 PM) | ||
@visisoft/staticland v.0.1.24 visisoft.de | ||
(Build date: 10/14/2021 - 3:36:52 PM) | ||
*/ | ||
@@ -31,3 +31,149 @@ 'use strict'; | ||
const | ||
// isJust :: Maybe a -> Boolean | ||
isJust = mx => Array.isArray(mx) && (mx.length === 1), // alt: mx !== singleNothing | ||
isNothing = mx => Array.isArray(mx) && (mx.length === 0); | ||
/** | ||
* Extract the value of a Just or return the provided default. | ||
* @function | ||
* @template T | ||
* @param {T} defaultValue | ||
* @param {Maybe<T>} maybe | ||
* @return {T} | ||
*/ | ||
// getOrElse :: a -> Maybe a -> a | ||
var getOrElse = semmelRamda.reduce((acc, x) => x); // alt: xs => xs[0] | ||
//map = curry((f, mx) => isJust(mx) ? mx.map(unary(f)) : singleNothing), // alt mx.map(unary(f)) | ||
// map :: (a -> b) -> Maybe a -> Maybe b | ||
var map = semmelRamda.curry((f, mx) => mx.map(semmelRamda.unary(f))); | ||
/** | ||
* Composition of `getOrElse` and `map`. | ||
* Transforms the value if it exists with the provided function. | ||
* Otherwise return the default value. | ||
* @function | ||
* @template T, U | ||
* @param {U} defaultValue | ||
* @param {function(T): U} | ||
* @return {function(Maybe<T>): U} | ||
*/ | ||
// maybe :: (() -> b) -> (a -> b) -> Maybe a -> b | ||
var maybe = semmelRamda.curry((nothingFn, justFn, ma) => | ||
isJust(ma) ? getOrElse("THIS_VALUE_SHOWING_ANYWHERE_IS_AN_ERROR", map(justFn, ma)) | ||
: nothingFn() | ||
); | ||
const | ||
// :: a -> Maybe a | ||
of = x => [x], | ||
//nothing = () => singleNothing, // TODO: alt: [] | ||
nothing = () => []; | ||
let just = of; | ||
// chain :: (a -> Maybe b) -> Maybe a -> Maybe b | ||
//chain = curry((f, mx) => isJust(mx) ? mx.flatMap(f) : singleNothing), | ||
//chain = curry((f, mx) => mx.flatMap(unary(f))), | ||
var chain = semmelRamda.curry((f, mx) => isJust(mx) ? f(mx[0]) : nothing()); | ||
var ap = semmelRamda.curry((mf, mx) => chain(f => map(f, mx), mf)); | ||
semmelRamda.curry((f, ma, mb) => ap(map(f, ma), mb)); | ||
/** | ||
* StaticLand: sequence.js | ||
* | ||
* Created by Matthias Seemann on 5.04.2021. | ||
* Copyright (c) 2021 Visisoft OHG. All rights reserved. | ||
*/ | ||
// :: Applicative f => ((a → f a), ((a → b) → f a → f b) → Maybe (f a) → f (Maybe a) | ||
const sequence$1 = semmelRamda.curry((of_f, map_f, mfa) => | ||
maybe( // :: (() -> b) -> (a -> b) -> Maybe a -> b | ||
semmelRamda.compose(of_f, nothing), // :: () -> f Nothing | ||
map_f(just), // :: f a -> f Just a | ||
mfa // :: Maybe f a | ||
) | ||
); | ||
semmelRamda.curry((of_f, map_f, effect_to_f, ma) => sequence$1(of_f, map_f, map(effect_to_f, ma))); | ||
/** | ||
* StaticLand: maybe.js | ||
* | ||
* Created by Matthias Seemann on 27.04.2020. | ||
* Copyright (c) 2020 Visisoft OHG. All rights reserved. | ||
*/ | ||
const | ||
// Creation // | ||
// fromNilable :: (a|undefined|null) -> Maybe a | ||
fromNilable = semmelRamda.ifElse(semmelRamda.isNil, nothing, of), | ||
// fromContentHolding :: a -> Maybe a | ||
fromContentHolding = semmelRamda.ifElse(semmelRamda.isEmpty, nothing, of), | ||
// :: (a -> Boolean) -> a -> Maybe a | ||
fromPredicate = semmelRamda.curry((predicate, x) => | ||
predicate(x) ? of(x) : nothing() | ||
), | ||
// Inspection // | ||
/** | ||
* Note that due to the implementation Maybes and empty or one-element arrays | ||
* cannot be separated from each other. Therefore | ||
* `equals(of(x), [x])` is `true` as well as `equals(nothing(), [])` is also `true`. | ||
*/ | ||
// equals :: Maybe a -> Maybe b -> Boolean | ||
equals = semmelRamda.curry((ma, mb) => | ||
isJust(ma) ? | ||
isJust(mb) && semmelRamda.equals(ma[0], mb[0]) : | ||
isNothing(mb) | ||
), | ||
// Side effects // | ||
/** | ||
* Note that probably `tap = tapR(maybe(() => undefined))` | ||
*/ | ||
// tap :: (a -> *) -> Maybe a -> Maybe a | ||
tap = semmelRamda.curry((fn, mx) => { | ||
mx.forEach(semmelRamda.unary(fn)); | ||
return mx; | ||
}), | ||
// Developer // | ||
typeString = maybe( | ||
semmelRamda.always('Nothing'), | ||
value => `Just(${semmelRamda.pathOr(typeof value, ['constructor', 'name'], value)})` | ||
); | ||
/** | ||
* StaticLand: find.js | ||
* | ||
* Created by Matthias Seemann on 14.10.2021. | ||
* Copyright (c) 2021 Visisoft OHG. All rights reserved. | ||
*/ | ||
const | ||
find = semmelRamda.curryN(2, (predicate, list) => { | ||
// shameless copy from Ramda | ||
let idx = 0; | ||
const len = list.length; | ||
while (idx < len) { | ||
if (predicate(list[idx])) { | ||
return just(list[idx]); | ||
} | ||
idx += 1; | ||
} | ||
return nothing(); | ||
}); | ||
exports.find = find; | ||
exports.sequence = sequence; | ||
exports.traverse = traverse; |
/* @license Apache-2.0 | ||
@visisoft/staticland v.0.1.23 visisoft.de | ||
(Build date: 10/4/2021 - 8:13:00 PM) | ||
@visisoft/staticland v.0.1.24 visisoft.de | ||
(Build date: 10/14/2021 - 3:36:52 PM) | ||
*/ | ||
@@ -5,0 +5,0 @@ 'use strict'; |
/* @license Apache-2.0 | ||
@visisoft/staticland v.0.1.23 visisoft.de | ||
(Build date: 10/4/2021 - 8:13:00 PM) | ||
@visisoft/staticland v.0.1.24 visisoft.de | ||
(Build date: 10/14/2021 - 3:36:52 PM) | ||
*/ | ||
@@ -5,0 +5,0 @@ 'use strict'; |
/* @license Apache-2.0 | ||
@visisoft/staticland v.0.1.23 visisoft.de | ||
(Build date: 10/4/2021 - 8:13:00 PM) | ||
@visisoft/staticland v.0.1.24 visisoft.de | ||
(Build date: 10/14/2021 - 3:36:52 PM) | ||
*/ | ||
@@ -698,2 +698,5 @@ 'use strict'; | ||
/** @deprecated | ||
* use maybe/sequence(of_p, map_p) | ||
*/ | ||
// maybeOfPromiseToPromiseOfMaybe :: Maybe Promise e a -> Promise e Maybe a | ||
@@ -896,6 +899,28 @@ maybeOfPromiseToPromiseOfMaybe = maybe(semmelRamda.compose(of, nothing), map_p(of$1)), | ||
/** | ||
* StaticLand: find.js | ||
* | ||
* Created by Matthias Seemann on 14.10.2021. | ||
* Copyright (c) 2021 Visisoft OHG. All rights reserved. | ||
*/ | ||
const | ||
find = semmelRamda.curryN(2, (predicate, list) => { | ||
// shameless copy from Ramda | ||
let idx = 0; | ||
const len = list.length; | ||
while (idx < len) { | ||
if (predicate(list[idx])) { | ||
return just(list[idx]); | ||
} | ||
idx += 1; | ||
} | ||
return nothing(); | ||
}); | ||
var list = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
sequence: sequence$1, | ||
traverse: traverse$1 | ||
traverse: traverse$1, | ||
find: find | ||
}); | ||
@@ -902,0 +927,0 @@ |
/* @license Apache-2.0 | ||
@visisoft/staticland v.0.1.23 visisoft.de | ||
(Build date: 10/4/2021 - 8:13:00 PM) | ||
@visisoft/staticland v.0.1.24 visisoft.de | ||
(Build date: 10/14/2021 - 3:36:52 PM) | ||
*/ | ||
@@ -506,2 +506,5 @@ 'use strict'; | ||
/** @deprecated | ||
* use maybe/sequence(of_p, map_p) | ||
*/ | ||
// maybeOfPromiseToPromiseOfMaybe :: Maybe Promise e a -> Promise e Maybe a | ||
@@ -508,0 +511,0 @@ maybeOfPromiseToPromiseOfMaybe = maybe(semmelRamda.compose(of$1, nothing), map_p(of$2)), |
@@ -5,2 +5,6 @@ import {Either} from './either'; | ||
export function find<A>(predicate:(a: A) => boolean, list: Array<A>): Maybe<A>; | ||
export function find<A>(predicate:(a: A) => boolean): (list: Array<A>) => Maybe<A>; | ||
export function sequence<A, B, C>( | ||
@@ -7,0 +11,0 @@ ofF: (a: A) => Applicative<A>, |
@@ -94,3 +94,3 @@ { | ||
"type": "module", | ||
"version": "0.1.23" | ||
"version": "0.1.24" | ||
} |
@@ -5,4 +5,4 @@ import {BinaryCurriedFn} from './common'; | ||
export function bi_tap<T>(onFailure: (e: any) => void, onSuccess: (x?: T) => any, p: Promise<T>): Promise<T>; | ||
export function bi_tap<T>(onFailure: (e: any) => void, onSuccess: (x?: T) => any): (p: Promise<T>) => Promise<T>; | ||
export function bi_tap<T>(onFailure: (e: any) => void, onSuccess: (t?: T) => any, p: Promise<T>): Promise<T>; | ||
export function bi_tap<T>(onFailure: (e: any) => void, onSuccess: (t?: T) => any): (p: Promise<T>) => Promise<T>; | ||
@@ -37,2 +37,4 @@ /** | ||
export function of<T>(x: T): Promise<T>; | ||
/** | ||
@@ -39,0 +41,0 @@ * calls the function with the success value, ignoring the return value. |
@@ -5,2 +5,6 @@ import {Either} from './either'; | ||
export function find<A>(predicate:(a: A) => boolean, list: Array<A>): Maybe<A>; | ||
export function find<A>(predicate:(a: A) => boolean): (list: Array<A>) => Maybe<A>; | ||
export function sequence<A, B, C>( | ||
@@ -7,0 +11,0 @@ ofF: (a: A) => Applicative<A>, |
export {default as sequence} from './list/sequence.js'; | ||
export {default as traverse} from './list/traverse.js'; | ||
export {default as find} from './list/find.js'; |
@@ -5,4 +5,4 @@ import {BinaryCurriedFn} from './common'; | ||
export function bi_tap<T>(onFailure: (e: any) => void, onSuccess: (x?: T) => any, p: Promise<T>): Promise<T>; | ||
export function bi_tap<T>(onFailure: (e: any) => void, onSuccess: (x?: T) => any): (p: Promise<T>) => Promise<T>; | ||
export function bi_tap<T>(onFailure: (e: any) => void, onSuccess: (t?: T) => any, p: Promise<T>): Promise<T>; | ||
export function bi_tap<T>(onFailure: (e: any) => void, onSuccess: (t?: T) => any): (p: Promise<T>) => Promise<T>; | ||
@@ -37,2 +37,4 @@ /** | ||
export function of<T>(x: T): Promise<T>; | ||
/** | ||
@@ -39,0 +41,0 @@ * calls the function with the success value, ignoring the return value. |
@@ -43,2 +43,5 @@ /** | ||
/** @deprecated | ||
* use maybe/sequence(of_p, map_p) | ||
*/ | ||
// maybeOfPromiseToPromiseOfMaybe :: Maybe Promise e a -> Promise e Maybe a | ||
@@ -45,0 +48,0 @@ maybeOfPromiseToPromiseOfMaybe = maybe(compose(of_p, nothing), map_p(of_mb)), |
128620
73
3326