main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | import { curry, map, tap } from 'ramda';
|
---|
2 |
|
---|
3 | /* eslint-disable max-len */
|
---|
4 | /**
|
---|
5 | * Runs the given list of functions in order with the supplied object, then returns the object.
|
---|
6 | * Also known as the normal order sequencing combinator.
|
---|
7 | *
|
---|
8 | * Acts as a transducer if a transformer is given as second parameter.
|
---|
9 | *
|
---|
10 | * @func seq
|
---|
11 | * @aliases sequencing
|
---|
12 | * @memberOf RA
|
---|
13 | * @since {@link https://char0n.github.io/ramda-adjunct/2.3.0|v2.3.0}
|
---|
14 | * @category Function
|
---|
15 | * @sig [(a -> *), (a -> *), ...] -> a -> a
|
---|
16 | * @param {Array} fns The list of functions to call in order with `x` whose return values will be thrown away
|
---|
17 | * @param {*} x
|
---|
18 | * @return {*} `x`
|
---|
19 | * @see {@link http://ramdajs.com/docs/#tap|R.tap}, {@link http://www.cs.rpi.edu/academics/courses/spring11/proglang/handouts/lambda-calculus-chapter.pdf|sequencing combinator explained}
|
---|
20 | * @example
|
---|
21 | *
|
---|
22 | * RA.seq([console.info, console.log])('foo'); //=> prints 'foo' via info then log
|
---|
23 | *
|
---|
24 | * // usage in composition
|
---|
25 | * R.pipe(
|
---|
26 | * R.concat('prefix '),
|
---|
27 | * RA.seq([
|
---|
28 | * console.info, //=> prints 'prefix test'
|
---|
29 | * console.log //=> prints 'prefix test'
|
---|
30 | * ]),
|
---|
31 | * R.toUpper
|
---|
32 | * )('test'); //=> 'PREFIX TEST'
|
---|
33 | */
|
---|
34 | /* eslint-enable max-len */
|
---|
35 |
|
---|
36 | const seq = curry((fns, x) => tap((tx) => map((fn) => fn(tx))(fns))(x));
|
---|
37 |
|
---|
38 | export default seq;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.