Last active
August 27, 2024 14:51
-
-
Save yurkimus/31fa2d7bf3c284b1d8ce92aab413f5c3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { curry } from '@yurkimus/curry' | |
import { isLike } from '@yurkimus/types' | |
export var chain = curry( | |
(predicate0, predicate1, ...parameters) => { | |
if (!isLike('Function', predicate0)) { | |
throw new TypeError('"predicate0" must be a function') | |
} | |
if (!isLike('Function', predicate1)) { | |
throw new TypeError('"predicate1" must be a function') | |
} | |
return predicate0(predicate1(...parameters), ...parameters) | |
}, | |
3, | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { isLike } from '@yurkimus/types' | |
/** | |
* @template {*} Parameter | |
* | |
* @param {Parameter} parameter | |
*/ | |
export var promiseOf = (parameter) => { | |
if (isLike('Function', parameter)) { | |
try { | |
return Promise.resolve(predicate()) | |
} catch (reason) { | |
return Promise.reject(reason) | |
} | |
} | |
return Promise.resolve(parameter) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment