…from Core.Lambda
Core.Lambda
provided basic operations to combine and transform functions. Most of the important ones are still available in Folktale 2, but under a different module. This page provides migration instructions for each function in Core.Lambda
. You can look at the full documentation for core/lambda
for more detailed information.
Contents
- identity(x)
- constant(x)(_)
- apply(f, x)
- flip(f)(b)(a)
- compose(f, g)(x)
- curry(arity, f)
- spread(f, args)
- uncurry(f)
- upon(f, g)(a, b)
identity(x)
The identity
function remains the same in Folktale, so the only change required is changing the import expression for it.
Previously:
Now:
constant(x)(_)
Folktale 2 provides a simpler form of constant
, which does no unrolling. If you’re not passing 2 arguments to constant
, the only thing you need to do is change your import.
Previously:
Now:
If you’re relying on the unrolling behaviour, see curry(arity, f)
.
apply(f, x)
There’s no equivalent of apply
in the Folktale 2. apply
is generally the same as just referring to the function directly:
flip(f)(b)(a)
There’s no equivalent of flip
in Folktale 2. Instead you should create a new function that changes the ordering of the parameters using an arrow function.
Previously:
Now:
compose(f, g)(x)
Folktale 2 provides a compose
function without the unrolling semantics. See the compose
documentation for details.
If you’re using compose
in the form compose(f, g)(x)
, then you only need to change your imports:
Previously:
Now:
If you’re using a single saturated call, you can either simplify the expression, or pass the argument as a separate call.
Previously:
Now:
If you’re specifying just one of the functions to compose, or some other uncommon partial application, create a new function explicitly instead.
Previously:
Now:
curry(arity, f)
Folktale 2 provides a curry
function that’s very similar to the old one, with the difference that it’ll only unroll up to the provided arity. This avoids problems with Folktale trying to unroll application of non-curried function when interacting with variadic functions in JavaScript (for example, with Array#map
). See the curry
documentation for details.
The only thing you need to do is changing your imports.
Previously:
Now:
spread(f, args)
Folktale 2 does not provide a spread
equivalent. You can use an arrow function instead to apply an array as positional arguments.
Previously:
Now:
uncurry(f)
Folktale 2 does not provide an uncurry
equivalent, since curried functions are avoided through the library. In any case, uncurry
is not necessary for functions curried with the curry
operation, which already does unrolling.
Previously:
Now:
upon(f, g)(a, b)
There’s no equivalent of upon
in Folktale 2, use an arrow function.
Previously:
Now: