Last active
October 11, 2018 10:17
-
-
Save WaldoJeffers/ff46fe25f3970e3ecc9c9401e5ce4f18 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
// SUBJECT | |
// Write a function withParamTransform which, | |
// for any function f, | |
// for any parameter transformation such as (a, b, c) => (a, c, b) (inverting 2 parameters) | |
// satisfies the following condition: | |
withParamTransform(f)[(a, b, c) => (a, c, b)](1, 2, 3) === f(1, 3, 2) | |
// A more realistic example | |
const minus = (a, b) => a - b | |
minus(5, 2) === 3 // true | |
withParamTransform(minus)[(a, b) => (b, a)](2, 5) === 3 // true | |
// Example use case | |
import { append } from 'ramda' | |
// append(3, [1, 2]) == [1, 2, 3] | |
const transformedAppend = withParamTransform(append) | |
const arr = ['you', 'we', 'they'] | |
arr.reduce(transformedAppend[(acc, val) => (val + ' are', acc)], []) | |
// ['you are', 'we are', ' they are'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment