Skip to content

Instantly share code, notes, and snippets.

@yurkimus
Last active August 27, 2024 14:51
Show Gist options
  • Save yurkimus/31fa2d7bf3c284b1d8ce92aab413f5c3 to your computer and use it in GitHub Desktop.
Save yurkimus/31fa2d7bf3c284b1d8ce92aab413f5c3 to your computer and use it in GitHub Desktop.
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,
)
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