These are chat archives for ramda/ramda

4th
Jul 2016
Emilio Srougo
@Emilios1995
Jul 04 2016 17:01
Hi, I'm having trouble understanding the difference between using `map` and `lift` on a functor
Emilio Srougo
@Emilios1995
Jul 04 2016 17:06
I learned about `lift` in The Little Idea of Functional Programming but don't understand why he couldn't use `map` instead
David Chambers
@davidchambers
Jul 04 2016 18:52
@ram-bot
``R.map(S.inc, [1, 2, 3])``
ram-bot
@ram-bot
Jul 04 2016 18:52
``[ 2, 3, 4 ]``
David Chambers
@davidchambers
Jul 04 2016 18:53
@ram-bot
``S.lift(S.inc, [1, 2, 3])``
ram-bot
@ram-bot
Jul 04 2016 18:53
``[ 2, 3, 4 ]``
David Chambers
@davidchambers
Jul 04 2016 18:55
`map` is equivalent to `lift` for unary functions, @Emilios1995. The nice thing about lifting, though, is it also works for functions of higher arities (see `lift2` and `lift3`).

Here’s an implementation of `lift3`, for example:

``function(f, x, y, z) { return R.ap(R.ap(R.map(f, x), y), z); }``

Lifting involves one `map` operation and N − 1 `ap` operations.

Emilio Srougo
@Emilios1995
Jul 04 2016 19:03
Oh, I understand now! So, it seems that the author of said blog post used `lift` unnecessary , right?
David Chambers
@davidchambers
Jul 04 2016 19:09
Although `map` and `lift` are equivalent, one tends to think about them a little differently. Somehow “lift” emphasizes the transformation of a function whereas we think of “map” as a transformation of a functor. Perhaps the author chose to use `lift` for this reason.
Emilio Srougo
@Emilios1995
Jul 04 2016 19:11
Yeah, it kinda makes sense. Thanks!