Search code examples
scalascala-cats

Functor for sequence computation


I am reading scala cats book from underscore.io. It says following about Monad and Functor:

While monads and functors are the most widely used sequencing data types..

I can see that Monad is using for sequencing data but Functor not at all. Could someone please show about sequencing computation on functors?


Solution

  • Seq(1, 2, 3).map(_ * 2).map(_.toString).foreach(println)
    

    Here: you have a sequence of operations on a sequence of data.

    Every monad is actually a functor, because you could implement map with flatMap and unit/pure/whatever your implementation calls it. So if you agree that monads are "sequencing data types", then you should agree on functors being them too.