@visisoft/staticland
Advanced tools
Comparing version 0.1.20 to 0.1.21
@@ -12,1 +12,4 @@ export type BinaryCurriedFn<S, T, U> = (s: T) => (t: T) => U; | ||
export type Function6<T1, T2, T3, T4, T5, T6, R> = (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6) => R; | ||
export type PlainObject = { [name: string]: any } | ||
export type PlainObjectOf<T> = { [name: string]: T } |
/* @license Apache-2.0 | ||
@visisoft/staticland v.0.1.20 visisoft.de | ||
(Build date: 3/21/2021 - 7:34:44 PM) | ||
@visisoft/staticland v.0.1.21 visisoft.de | ||
(Build date: 4/15/2021 - 9:42:54 PM) | ||
*/ | ||
@@ -5,0 +5,0 @@ 'use strict'; |
/* @license Apache-2.0 | ||
@visisoft/staticland v.0.1.20 visisoft.de | ||
(Build date: 3/21/2021 - 7:34:44 PM) | ||
@visisoft/staticland v.0.1.21 visisoft.de | ||
(Build date: 4/15/2021 - 9:42:54 PM) | ||
*/ | ||
@@ -5,0 +5,0 @@ 'use strict'; |
/* @license Apache-2.0 | ||
@visisoft/staticland v.0.1.20 visisoft.de | ||
(Build date: 3/21/2021 - 7:34:44 PM) | ||
@visisoft/staticland v.0.1.21 visisoft.de | ||
(Build date: 4/15/2021 - 9:42:54 PM) | ||
*/ | ||
@@ -11,5 +11,74 @@ '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)); | ||
var liftA2 = 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 = 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 | ||
) | ||
); | ||
var traverse = semmelRamda.curry((of_f, map_f, effect_to_f, ma) => sequence(of_f, map_f, map(effect_to_f, ma))); | ||
/** | ||
* StaticLand: maybe.js | ||
@@ -24,7 +93,2 @@ * | ||
// :: a -> Maybe a | ||
of = x => [x], | ||
//nothing = () => singleNothing, // TODO: alt: [] | ||
nothing = () => [], | ||
// fromNilable :: (a|undefined|null) -> Maybe a | ||
@@ -43,6 +107,2 @@ fromNilable = semmelRamda.ifElse(semmelRamda.isNil, nothing, of), | ||
// isJust :: Maybe a -> Boolean | ||
isJust = mx => Array.isArray(mx) && (mx.length === 1), // alt: mx !== singleNothing | ||
isNothing = mx => Array.isArray(mx) && (mx.length === 0), | ||
/** | ||
@@ -73,11 +133,2 @@ * Note that due to the implementation Maybes and empty or one-element arrays | ||
//map = curry((f, mx) => isJust(mx) ? mx.map(unary(f)) : singleNothing), // alt mx.map(unary(f)) | ||
// map :: (a -> b) -> Maybe a -> Maybe b | ||
map = semmelRamda.curry((f, mx) => mx.map(semmelRamda.unary(f))), | ||
// 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))), | ||
chain = semmelRamda.curry((f, mx) => isJust(mx) ? f(mx[0]) : nothing()), | ||
ap = semmelRamda.curry((mf, mx) => chain(f => map(f, mx), mf)), | ||
reduce = semmelRamda.reduce,//curry((f, initial, mx) => mx.reduce(f, initial)), | ||
@@ -96,34 +147,2 @@ | ||
// Consumption // | ||
/** | ||
* 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 | ||
getOrElse = reduce((acc, x) => x), // alt: xs => xs[0] | ||
// maybe :: b -> (a -> b) -> Maybe a -> b | ||
//maybe = curry((defaultValue, justFn, ma) => getOrElse(defaultValue, map(justFn, ma))), | ||
/** | ||
* 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 | ||
maybe = semmelRamda.curry((nothingFn, justFn, ma) => | ||
isJust(ma) ? getOrElse("THIS_VALUE_SHOWING_ANYWHERE_IS_AN_ERROR", map(justFn, ma)) | ||
: nothingFn() | ||
), | ||
// Adjuncts // | ||
@@ -159,4 +178,2 @@ | ||
let just = of; | ||
exports.ap = ap; | ||
@@ -180,3 +197,5 @@ exports.chain = chain; | ||
exports.reduce = reduce; | ||
exports.sequence = sequence; | ||
exports.tap = tap; | ||
exports.traverse = traverse; | ||
exports.typeString = typeString; |
/* @license Apache-2.0 | ||
@visisoft/staticland v.0.1.20 visisoft.de | ||
(Build date: 3/21/2021 - 7:34:44 PM) | ||
@visisoft/staticland v.0.1.21 visisoft.de | ||
(Build date: 4/15/2021 - 9:42:54 PM) | ||
*/ | ||
@@ -41,2 +41,15 @@ 'use strict'; | ||
/** | ||
* WebRTCPeer: later.js | ||
* | ||
* Created by Matthias Seemann on 6.02.2021. | ||
* Copyright (c) 2021 Visisoft OHG. All rights reserved. | ||
*/ | ||
const | ||
// later :: Number -> t -> Promise e t | ||
later = semmelRamda.curry((dt, value) => new Promise(resolve => | ||
setTimeout(resolve, dt, value) | ||
)); | ||
var liftA2 = semmelRamda.curry((f, ma, mb) => ap_p(map(f, ma), mb)); | ||
@@ -274,2 +287,3 @@ | ||
exports.join = join; | ||
exports.later = later; | ||
exports.liftA2 = liftA2; | ||
@@ -276,0 +290,0 @@ exports.map = map; |
/* @license Apache-2.0 | ||
@visisoft/staticland v.0.1.20 visisoft.de | ||
(Build date: 3/21/2021 - 7:34:44 PM) | ||
@visisoft/staticland v.0.1.21 visisoft.de | ||
(Build date: 4/15/2021 - 9:42:54 PM) | ||
*/ | ||
@@ -42,2 +42,15 @@ 'use strict'; | ||
/** | ||
* WebRTCPeer: later.js | ||
* | ||
* Created by Matthias Seemann on 6.02.2021. | ||
* Copyright (c) 2021 Visisoft OHG. All rights reserved. | ||
*/ | ||
const | ||
// later :: Number -> t -> Promise e t | ||
later = semmelRamda.curry((dt, value) => new Promise(resolve => | ||
setTimeout(resolve, dt, value) | ||
)); | ||
var liftA2 = semmelRamda.curry((f, ma, mb) => ap_p(map_p(f, ma), mb)); | ||
@@ -285,8 +298,78 @@ | ||
ap: ap_p, | ||
later: later, | ||
liftA2: liftA2 | ||
}); | ||
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$1 = x => [x], | ||
//nothing = () => singleNothing, // TODO: alt: [] | ||
nothing = () => []; | ||
let just = of$1; | ||
// 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$1 = semmelRamda.curry((f, mx) => isJust(mx) ? f(mx[0]) : nothing()); | ||
var ap = semmelRamda.curry((mf, mx) => chain$1(f => map(f, mx), mf)); | ||
var liftA2$1 = 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 = 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 | ||
) | ||
); | ||
var traverse = semmelRamda.curry((of_f, map_f, effect_to_f, ma) => sequence(of_f, map_f, map(effect_to_f, ma))); | ||
/** | ||
* StaticLand: maybe.js | ||
@@ -301,7 +384,2 @@ * | ||
// :: a -> Maybe a | ||
of$1 = x => [x], | ||
//nothing = () => singleNothing, // TODO: alt: [] | ||
nothing = () => [], | ||
// fromNilable :: (a|undefined|null) -> Maybe a | ||
@@ -320,6 +398,2 @@ fromNilable = semmelRamda.ifElse(semmelRamda.isNil, nothing, of$1), | ||
// isJust :: Maybe a -> Boolean | ||
isJust = mx => Array.isArray(mx) && (mx.length === 1), // alt: mx !== singleNothing | ||
isNothing = mx => Array.isArray(mx) && (mx.length === 0), | ||
/** | ||
@@ -350,11 +424,2 @@ * Note that due to the implementation Maybes and empty or one-element arrays | ||
//map = curry((f, mx) => isJust(mx) ? mx.map(unary(f)) : singleNothing), // alt mx.map(unary(f)) | ||
// map :: (a -> b) -> Maybe a -> Maybe b | ||
map = semmelRamda.curry((f, mx) => mx.map(semmelRamda.unary(f))), | ||
// 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))), | ||
chain$1 = semmelRamda.curry((f, mx) => isJust(mx) ? f(mx[0]) : nothing()), | ||
ap = semmelRamda.curry((mf, mx) => chain$1(f => map(f, mx), mf)), | ||
reduce = semmelRamda.reduce,//curry((f, initial, mx) => mx.reduce(f, initial)), | ||
@@ -373,34 +438,2 @@ | ||
// Consumption // | ||
/** | ||
* 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 | ||
getOrElse = reduce((acc, x) => x), // alt: xs => xs[0] | ||
// maybe :: b -> (a -> b) -> Maybe a -> b | ||
//maybe = curry((defaultValue, justFn, ma) => getOrElse(defaultValue, map(justFn, ma))), | ||
/** | ||
* 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 | ||
maybe = semmelRamda.curry((nothingFn, justFn, ma) => | ||
isJust(ma) ? getOrElse("THIS_VALUE_SHOWING_ANYWHERE_IS_AN_ERROR", map(justFn, ma)) | ||
: nothingFn() | ||
), | ||
// Adjuncts // | ||
@@ -436,4 +469,2 @@ | ||
let just = of$1; | ||
var maybe$1 = /*#__PURE__*/Object.freeze({ | ||
@@ -445,2 +476,3 @@ __proto__: null, | ||
fromPredicate: fromPredicate, | ||
just: just, | ||
of: of$1, | ||
@@ -458,6 +490,7 @@ nothing: nothing, | ||
tap: tap$1, | ||
typeString: typeString, | ||
getOrElse: getOrElse, | ||
typeString: typeString, | ||
just: just, | ||
liftA2: liftA2$1 | ||
liftA2: liftA2$1, | ||
sequence: sequence, | ||
traverse: traverse | ||
}); | ||
@@ -612,2 +645,4 @@ | ||
// A specialisation of the Maybe sequence: | ||
// sequence(of_o, map_o) | ||
// :: Maybe Observable e a -> EventStream e Maybe a | ||
@@ -619,2 +654,4 @@ const maybeOfBaconObservableToBaconObservableOfMaybe = | ||
// A specialisation of the Maybe sequence: | ||
// sequence(of_c, map_c) | ||
var maybeOfCancelableToCancelableOfMaybe = maybe(semmelRamda.compose(of$3, nothing), map$2(just)); | ||
@@ -621,0 +658,0 @@ |
/* @license Apache-2.0 | ||
@visisoft/staticland v.0.1.20 visisoft.de | ||
(Build date: 3/21/2021 - 7:34:44 PM) | ||
@visisoft/staticland v.0.1.21 visisoft.de | ||
(Build date: 4/15/2021 - 9:42:54 PM) | ||
*/ | ||
@@ -104,2 +104,15 @@ 'use strict'; | ||
/** | ||
* WebRTCPeer: later.js | ||
* | ||
* Created by Matthias Seemann on 6.02.2021. | ||
* Copyright (c) 2021 Visisoft OHG. All rights reserved. | ||
*/ | ||
const | ||
// later :: Number -> t -> Promise e t | ||
later = semmelRamda.curry((dt, value) => new Promise(resolve => | ||
setTimeout(resolve, dt, value) | ||
)); | ||
semmelRamda.curry((f, ma, mb) => ap_p(map_p(f, ma), mb)); | ||
@@ -246,5 +259,74 @@ | ||
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$1 = 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$1(justFn, ma)) | ||
: nothingFn() | ||
); | ||
const | ||
// :: a -> Maybe a | ||
of$2 = x => [x], | ||
//nothing = () => singleNothing, // TODO: alt: [] | ||
nothing = () => []; | ||
let just = of$2; | ||
// 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$2 = semmelRamda.curry((f, mx) => isJust(mx) ? f(mx[0]) : nothing()); | ||
var ap = semmelRamda.curry((mf, mx) => chain$2(f => map$1(f, mx), mf)); | ||
semmelRamda.curry((f, ma, mb) => ap(map$1(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 = 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(of_f, map_f, map$1(effect_to_f, ma))); | ||
/** | ||
* StaticLand: maybe.js | ||
@@ -259,7 +341,2 @@ * | ||
// :: a -> Maybe a | ||
of$2 = x => [x], | ||
//nothing = () => singleNothing, // TODO: alt: [] | ||
nothing = () => [], | ||
// fromNilable :: (a|undefined|null) -> Maybe a | ||
@@ -278,6 +355,2 @@ fromNilable = semmelRamda.ifElse(semmelRamda.isNil, nothing, of$2), | ||
// isJust :: Maybe a -> Boolean | ||
isJust = mx => Array.isArray(mx) && (mx.length === 1), // alt: mx !== singleNothing | ||
isNothing = mx => Array.isArray(mx) && (mx.length === 0), | ||
/** | ||
@@ -295,13 +368,2 @@ * Note that due to the implementation Maybes and empty or one-element arrays | ||
//map = curry((f, mx) => isJust(mx) ? mx.map(unary(f)) : singleNothing), // alt mx.map(unary(f)) | ||
// map :: (a -> b) -> Maybe a -> Maybe b | ||
map$1 = semmelRamda.curry((f, mx) => mx.map(semmelRamda.unary(f))), | ||
// 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))), | ||
chain$2 = semmelRamda.curry((f, mx) => isJust(mx) ? f(mx[0]) : nothing()), | ||
ap = semmelRamda.curry((mf, mx) => chain$2(f => map$1(f, mx), mf)), | ||
reduce = semmelRamda.reduce,//curry((f, initial, mx) => mx.reduce(f, initial)), | ||
// Side effects // | ||
@@ -318,34 +380,2 @@ | ||
// Consumption // | ||
/** | ||
* 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 | ||
getOrElse = reduce((acc, x) => x), // alt: xs => xs[0] | ||
// maybe :: b -> (a -> b) -> Maybe a -> b | ||
//maybe = curry((defaultValue, justFn, ma) => getOrElse(defaultValue, map(justFn, ma))), | ||
/** | ||
* 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 | ||
maybe = semmelRamda.curry((nothingFn, justFn, ma) => | ||
isJust(ma) ? getOrElse("THIS_VALUE_SHOWING_ANYWHERE_IS_AN_ERROR", map$1(justFn, ma)) | ||
: nothingFn() | ||
), | ||
// Developer // | ||
@@ -358,4 +388,2 @@ | ||
let just = of$2; | ||
// :: Promise e a -> Cancelable e a | ||
@@ -424,2 +452,4 @@ const promiseToCancelable = promise => (res, rej) => { | ||
// A specialisation of the Maybe sequence: | ||
// sequence(of_o, map_o) | ||
// :: Maybe Observable e a -> EventStream e Maybe a | ||
@@ -431,2 +461,4 @@ const maybeOfBaconObservableToBaconObservableOfMaybe = | ||
// A specialisation of the Maybe sequence: | ||
// sequence(of_c, map_c) | ||
var maybeOfCancelableToCancelableOfMaybe = maybe(semmelRamda.compose(of$3, nothing), map_c(just)); | ||
@@ -433,0 +465,0 @@ |
@@ -1,2 +0,3 @@ | ||
import {BinaryCurriedFn, TernaryCurriedFn} from './common'; | ||
import {BinaryCurriedFn, PlainObjectOf, TernaryCurriedFn} from './common'; | ||
import {Either} from './either'; | ||
@@ -6,2 +7,3 @@ export type Just<T> = [T]; | ||
export type Maybe<T> = Just<T> | Nothing; | ||
type Applicative<T> = Promise<T>|Either<T>|PlainObjectOf<T>; | ||
@@ -43,2 +45,11 @@ /** | ||
export function sequence<A, B>( | ||
ofF: (a: A) => Applicative<A>, | ||
mapF: (f: (a: A) => B, ma: Applicative<A>) => Applicative<B>, | ||
mfa: Maybe<Applicative<A>>): Applicative<Maybe<A>>; | ||
export function sequence<A,B>( | ||
ofF: (a: A) => Applicative<A>, | ||
mapF: (f: (a: A) => B, ma: Applicative<A>) => Applicative<B>): | ||
(mfa: Maybe<Applicative<A>>) => Applicative<Maybe<A>>; | ||
export function tap<T>(fn: (x: T) => any, p: Maybe<T>): Maybe<T>; | ||
@@ -45,0 +56,0 @@ export function tap<T>(fn: (x: T) => any): (p: Maybe<T>) => Maybe<T>; |
@@ -44,2 +44,6 @@ { | ||
}, | ||
"./list": { | ||
"require": "./dist/cjs/list.js", | ||
"default": "./src/list.js" | ||
}, | ||
"./transformations": { | ||
@@ -91,3 +95,3 @@ "require": "./dist/cjs/transformations.js", | ||
"type": "module", | ||
"version": "0.1.20" | ||
"version": "0.1.21" | ||
} |
import {BinaryCurriedFn} from './common'; | ||
export function all<T>(promises: Array<Promise<T>>): Promise<Array<T>>; | ||
/** | ||
@@ -9,2 +11,5 @@ * Produce a Promise from the factory function and the resolution value of the promise | ||
export function later<A>(dt: number, a: A): Promise<A>; | ||
export function later<A>(dt: number): (a: A) => Promise<A>; | ||
/** | ||
@@ -11,0 +16,0 @@ * Makes a binary curried function accept and return Promises Types instead of Types |
@@ -12,1 +12,4 @@ export type BinaryCurriedFn<S, T, U> = (s: T) => (t: T) => U; | ||
export type Function6<T1, T2, T3, T4, T5, T6, R> = (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6) => R; | ||
export type PlainObject = { [name: string]: any } | ||
export type PlainObjectOf<T> = { [name: string]: T } |
@@ -1,2 +0,3 @@ | ||
import {BinaryCurriedFn, TernaryCurriedFn} from './common'; | ||
import {BinaryCurriedFn, PlainObjectOf, TernaryCurriedFn} from './common'; | ||
import {Either} from './either'; | ||
@@ -6,2 +7,3 @@ export type Just<T> = [T]; | ||
export type Maybe<T> = Just<T> | Nothing; | ||
type Applicative<T> = Promise<T>|Either<T>|PlainObjectOf<T>; | ||
@@ -43,2 +45,11 @@ /** | ||
export function sequence<A, B>( | ||
ofF: (a: A) => Applicative<A>, | ||
mapF: (f: (a: A) => B, ma: Applicative<A>) => Applicative<B>, | ||
mfa: Maybe<Applicative<A>>): Applicative<Maybe<A>>; | ||
export function sequence<A,B>( | ||
ofF: (a: A) => Applicative<A>, | ||
mapF: (f: (a: A) => B, ma: Applicative<A>) => Applicative<B>): | ||
(mfa: Maybe<Applicative<A>>) => Applicative<Maybe<A>>; | ||
export function tap<T>(fn: (x: T) => any, p: Maybe<T>): Maybe<T>; | ||
@@ -45,0 +56,0 @@ export function tap<T>(fn: (x: T) => any): (p: Maybe<T>) => Maybe<T>; |
@@ -18,2 +18,9 @@ /** | ||
import maybe from './maybe/maybe.js'; | ||
import {isJust, isNothing} from './maybe/inspection.js'; | ||
import map from './maybe/map.js'; | ||
import {just, of, nothing} from './maybe/creation.js'; | ||
import chain from './maybe/chain.js'; | ||
import ap from './maybe/ap.js'; | ||
const | ||
@@ -24,7 +31,2 @@ singleNothing = [], | ||
// :: a -> Maybe a | ||
of = x => [x], | ||
//nothing = () => singleNothing, // TODO: alt: [] | ||
nothing = () => [], | ||
// fromNilable :: (a|undefined|null) -> Maybe a | ||
@@ -43,6 +45,2 @@ fromNilable = ifElse(isNil, nothing, of), | ||
// isJust :: Maybe a -> Boolean | ||
isJust = mx => Array.isArray(mx) && (mx.length === 1), // alt: mx !== singleNothing | ||
isNothing = mx => Array.isArray(mx) && (mx.length === 0), | ||
/** | ||
@@ -73,11 +71,2 @@ * Note that due to the implementation Maybes and empty or one-element arrays | ||
//map = curry((f, mx) => isJust(mx) ? mx.map(unary(f)) : singleNothing), // alt mx.map(unary(f)) | ||
// map :: (a -> b) -> Maybe a -> Maybe b | ||
map = curry((f, mx) => mx.map(unary(f))), | ||
// 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))), | ||
chain = curry((f, mx) => isJust(mx) ? f(mx[0]) : nothing()), | ||
ap = curry((mf, mx) => chain(f => map(f, mx), mf)), | ||
reduce = reduce_l,//curry((f, initial, mx) => mx.reduce(f, initial)), | ||
@@ -96,34 +85,2 @@ | ||
// Consumption // | ||
/** | ||
* 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 | ||
getOrElse = reduce((acc, x) => x), // alt: xs => xs[0] | ||
// maybe :: b -> (a -> b) -> Maybe a -> b | ||
//maybe = curry((defaultValue, justFn, ma) => getOrElse(defaultValue, map(justFn, ma))), | ||
/** | ||
* 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 | ||
maybe = curry((nothingFn, justFn, ma) => | ||
isJust(ma) ? getOrElse("THIS_VALUE_SHOWING_ANYWHERE_IS_AN_ERROR", map(justFn, ma)) | ||
: nothingFn() | ||
), | ||
// Adjuncts // | ||
@@ -160,8 +117,10 @@ | ||
export { | ||
equals, fromNilable, fromContentHolding, fromPredicate, of, nothing, isJust, isNothing, join, lift, | ||
map, maybe, chain, ap, reduce, tap, getOrElse, | ||
equals, fromNilable, fromContentHolding, fromPredicate, just, of, nothing, isJust, isNothing, join, lift, | ||
map, maybe, chain, ap, reduce, tap, | ||
typeString | ||
}; | ||
export let just = of; | ||
export {default as getOrElse} from './maybe/getOrElse.js'; | ||
export {default as liftA2} from './maybe/liftA2.js'; | ||
export {default as sequence} from './maybe/sequence.js'; | ||
export {default as traverse} from './maybe/traverse.js'; |
import {curry} from "semmel-ramda"; | ||
import {ap, map} from "../maybe.js"; | ||
import ap from "./ap.js"; | ||
import map from './map.js'; | ||
export default curry((f, ma, mb) => ap(map(f, ma), mb)); |
import {BinaryCurriedFn} from './common'; | ||
export function all<T>(promises: Array<Promise<T>>): Promise<Array<T>>; | ||
/** | ||
@@ -9,2 +11,5 @@ * Produce a Promise from the factory function and the resolution value of the promise | ||
export function later<A>(dt: number, a: A): Promise<A>; | ||
export function later<A>(dt: number): (a: A) => Promise<A>; | ||
/** | ||
@@ -11,0 +16,0 @@ * Makes a binary curried function accept and return Promises Types instead of Types |
@@ -225,2 +225,3 @@ /** | ||
export {default as ap} from './promise/ap.js'; | ||
export {default as later} from './promise/internal/laterSucceed.js'; | ||
export {default as liftA2} from './promise/liftA2.js'; | ||
@@ -227,0 +228,0 @@ |
@@ -5,2 +5,3 @@ import {EventStream, Observable } from "baconjs"; | ||
import {Either} from "./either"; | ||
import {PlainObject} from "./common"; | ||
@@ -12,2 +13,7 @@ export function cancelableToEventStream<A>(ca: Cancelable<A>): EventStream<A>; | ||
export function keyMaybeToMaybeObj(key: string, moa: PlainObject): Maybe<PlainObject>; | ||
export function keyMaybeToMaybeObj(key: string): (moa: PlainObject) => Maybe<PlainObject>; | ||
export function keyMaybeToMaybeObj(index: number, maa: Array<any>): Maybe<Array<any>>; | ||
export function keyMaybeToMaybeObj(index: number): (maa: Array<any>) => Maybe<Array<any>>; | ||
export function maybeOfBaconObservableToBaconObservableOfMaybe<A>(mma: Maybe<Observable<A>>): EventStream<Maybe<A>>; | ||
@@ -14,0 +20,0 @@ |
@@ -5,2 +5,4 @@ import {maybe, of as of_mb, nothing} from "../maybe.js"; | ||
// A specialisation of the Maybe sequence: | ||
// sequence(of_o, map_o) | ||
// :: Maybe Observable e a -> EventStream e Maybe a | ||
@@ -7,0 +9,0 @@ const maybeOfBaconObservableToBaconObservableOfMaybe = |
@@ -6,2 +6,4 @@ import {compose} from "semmel-ramda"; | ||
// A specialisation of the Maybe sequence: | ||
// sequence(of_c, map_c) | ||
export default maybe(compose(of_c, nothing), map_c(just)); |
@@ -5,2 +5,3 @@ import {EventStream, Observable } from "baconjs"; | ||
import {Either} from "./either"; | ||
import {PlainObject} from "./common"; | ||
@@ -12,2 +13,7 @@ export function cancelableToEventStream<A>(ca: Cancelable<A>): EventStream<A>; | ||
export function keyMaybeToMaybeObj(key: string, moa: PlainObject): Maybe<PlainObject>; | ||
export function keyMaybeToMaybeObj(key: string): (moa: PlainObject) => Maybe<PlainObject>; | ||
export function keyMaybeToMaybeObj(index: number, maa: Array<any>): Maybe<Array<any>>; | ||
export function keyMaybeToMaybeObj(index: number): (maa: Array<any>) => Maybe<Array<any>>; | ||
export function maybeOfBaconObservableToBaconObservableOfMaybe<A>(mma: Maybe<Observable<A>>): EventStream<Maybe<A>>; | ||
@@ -14,0 +20,0 @@ |
118826
71
3021