1

Leonardo Borges has written an excellent post called "Functional Composition With Monads, Kleislis and Functors".

In it he comments:

Mark pointed out to me that lift is pretty much the same as map but with the arguments reversed.

This means that this:

val f = Functor[Option].lift(parts) compose make

can be refactored to:

val g = make(_:Int).map(parts)

My question is,What does it mean that 'lift is pretty much the same as map?'

hawkeye
  • 34,745
  • 30
  • 150
  • 304
  • I'd even rather say that `map` is just a flipped `lift`. Scala is the only language I know of that uses that order of arguments: Consider Python's `map`, Haskell's `fmap`, Lisp's `mapcar`... they're all in `lift`'s order. That probably comes from Scala's tendency to infix notation. – phipsgabler Jun 23 '14 at 09:04

1 Answers1

3

From scalaz functor code:

def map[A, B](fa: F[A])(f: A => B): F[B]

def lift[A, B](f: A => B): F[A] => F[B] = map(_)(f)

NOTE: lift is just defined in terms of map (reversing the arguments)

Mostly when people start with Functional programming they are introduced to map as mapping a function over a sequence of things, but map in general is a more abstract concept related to functor.

Ankur
  • 33,367
  • 2
  • 46
  • 72