Sequencing combinator (not S-combinator)
See original GitHub issueThe seq combinator is used to loop over a sequence of functions. It takes two or more functions as parameters and returns a new function, which runs all of them in sequence against the same value. This is the implementation:
const seq = function(/*funcs*/) {
const funcs = Array.prototype.slice.call(arguments);
return function (val) {
funcs.forEach(function (fn) {
fn(val);
});
};
};
With it, you can perform a sequence of related, yet independent, operations. For instance, after finding the student object, you can use seq to both render it on the HTML page and log it to the console. All functions will run in that order against the same student object:
const showStudent = R.compose(
seq(
append('#student-info'),
consoleLog),
csv,
findStudent));
The seq combinator doesn’t return a value; it just performs a set of actions one after the other. If you want to inject it into the middle of a composition, you can use R.tap to bridge the function with the rest.
From page 114 of Functional Programming in JavaScript
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (5 by maintainers)
Ok as far as I understand, Luis Atencios explanation is incorrect ? It seems like that this is the case. S-combinator works a bit different than Luis implemented it. Or in different words: he implements only subset of what S-combinator should be ? Anyway I would like to invite Luis to participate in this debate so that we get it right. And it also seems that we already have an S-combinator in ramda implemented as
ap
:This works exactly as you described the S-combinator.
Ok nice research. So there are two combinators, S-combinator and Sequencing combinator. I see them as two completely different things. Let’s implement the sequencing combinator here and heal with the rest in #250