You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Lift is like `map` except it can be applied to multiple functors.
318
+
Lifting is when you take a value and put it into an object like a [functor](#pointed-functor). If you lift a function into an [Applicative Functor](#applicative-functor) then you can make it work on values that are also in that functor.
319
319
320
-
Map is the same as a lift over a one-argument function:
320
+
Some implementations have a function called `lift`, or `liftA2` to make it easier to run functions on functors.
321
321
322
322
```js
323
-
lift((n) => n *2)([2, 3, 4]); // [4, 6, 8]
323
+
constmult= (a, b) => a * b;
324
+
325
+
constliftedMult=lift(mult); // this function now works on functors like array
326
+
327
+
liftedMult([1, 2], [3]); // [3, 6]
328
+
lift((a, b) => a + b)([1, 2], [3, 4]); // [4, 5, 5, 6]
324
329
```
325
330
326
-
Unlike map lift can be used to combine values from multiple arrays:
331
+
Lifting a one-argument function and applying it does the same thing as `map`.
327
332
328
333
```js
329
-
lift((a, b) => a * b)([1, 2], [3]); // [3, 6]
330
-
lift((a, b) => a * b)([1, 2], [3, 4]); // [3, 6, 4, 8]
334
+
constincrement= (x) => x +1;
335
+
336
+
lift(increment)([2]); // [3]
337
+
[2].map(increment); // [3]
331
338
```
332
339
340
+
333
341
## Referential Transparency
334
342
335
343
An expression that can be replaced with its value without changing the
@@ -456,6 +464,24 @@ An applicative functor is an object with an `ap` function. `ap` applies a functi
456
464
[(a) => a +1].ap([1]) // [2]
457
465
```
458
466
467
+
This is useful if you have multiple applicative functors and you want to apply a function that takes multiple arguments to them.
0 commit comments