added applyTo (name stolen from ramda)
This commit is contained in:
parent
c545be05ea
commit
bcc2d003bf
1 changed files with 9 additions and 13 deletions
|
@ -1,6 +1,6 @@
|
||||||
import { curry, curryN } from './curry.js'
|
import { curry, curryN } from './curry.js'
|
||||||
import { dispatch } from './fantasy-land.js'
|
import { dispatch } from './fantasy-land.js'
|
||||||
import { concat as iconcat, isIterable, iter, tail } from './list.js'
|
import { head, concat as iconcat, isIterable, iter, tail } from './list.js'
|
||||||
|
|
||||||
/** @import { Fn, Morphism, InferredMorphism, Predicate } from './types.js' */
|
/** @import { Fn, Morphism, InferredMorphism, Predicate } from './types.js' */
|
||||||
|
|
||||||
|
@ -11,17 +11,6 @@ import { concat as iconcat, isIterable, iter, tail } from './list.js'
|
||||||
*/
|
*/
|
||||||
export const id = x => x
|
export const id = x => x
|
||||||
|
|
||||||
export const tap = curry((f, x) => {
|
|
||||||
f(x)
|
|
||||||
return x
|
|
||||||
})
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {...Fn} fns
|
|
||||||
* @returns {(x: any) => any}
|
|
||||||
*/
|
|
||||||
export const pipe = (...fns) => (...args) => tail(fns).reduce((v, f) => f(v), head(fns)(...args))
|
|
||||||
|
|
||||||
export const concat = dispatch(['fantasy-land/concat', 'concat'],
|
export const concat = dispatch(['fantasy-land/concat', 'concat'],
|
||||||
(b, a) => {
|
(b, a) => {
|
||||||
if (isIterable(a) || isIterable(b)) {
|
if (isIterable(a) || isIterable(b)) {
|
||||||
|
@ -121,7 +110,6 @@ export const unless = curry(
|
||||||
* @template {Morphism<A, B>} [F=Morphism<A, B>]
|
* @template {Morphism<A, B>} [F=Morphism<A, B>]
|
||||||
* @typedef {(f: F, a: A) => B} StaticMorphism
|
* @typedef {(f: F, a: A) => B} StaticMorphism
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const ap = dispatch(['fantasy-land/ap', 'ap'],
|
export const ap = dispatch(['fantasy-land/ap', 'ap'],
|
||||||
/**
|
/**
|
||||||
* @template A, B
|
* @template A, B
|
||||||
|
@ -140,6 +128,8 @@ export const ap = dispatch(['fantasy-land/ap', 'ap'],
|
||||||
return [...xs]
|
return [...xs]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const applyTo = flip(ap)
|
||||||
|
|
||||||
export const chain = dispatch(['fantasy-land/chain', 'chain'],
|
export const chain = dispatch(['fantasy-land/chain', 'chain'],
|
||||||
(f, a) => f(a)
|
(f, a) => f(a)
|
||||||
)
|
)
|
||||||
|
@ -167,3 +157,9 @@ export const tee = curry((f, x) => {
|
||||||
return x
|
return x
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {...Fn} fns
|
||||||
|
* @returns {(x: any) => any}
|
||||||
|
*/
|
||||||
|
export const pipe = (...fns) => (...args) => reduce((v, f) => f(v), head(fns)(...args), tail(fns))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue