Last active
January 10, 2018 22:01
-
-
Save jrsinclair/e6a9767bce66aa8797770f527e69ae5c to your computer and use it in GitHub Desktop.
This file contains 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 'lodash/fp'; | |
/** | |
* Chain (flatMap) for Functions. | |
* | |
* chainf: (a -> x -> b) -> (x -> a) -> x -> b | |
* | |
* @param {Function} g A function that takes two parameters of type a and x. | |
* @param {Function} h A function that takes one paramter of type x. | |
* @param {*} x A value of type x. | |
* @return {*} g(h(x), x) | |
*/ | |
const chainf = curry(function chainf(g, h, x) { // eslint-disable-line prefer-arrow-callback | |
return g(h(x), x); | |
}); | |
// This can also be written in the following way, which might be clearer. | |
// chainf: (a -> x -> b) -> (x -> a) -> (x -> b) | |
// const chainf = curry(function chainf(g, h) { | |
// return x => g(h(x), x); | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment