List(1, 2, 3)
[1, 2, 3]
(1 to 10).toList
[1 .. 10]
(1 to 10).toList.map(x => x * x)
map (\x -> x * x) [1 .. 10]
map
is defined only for list:
map :: (a -> b) -> [a] -> [b]
fmap (\x -> x * x) [1 .. 10]
fmap
is defined in terms of Functor:
fmap :: Functor f => (a -> b) -> f a -> f b
(\x -> x * x) <$> [1 .. 10]
<$>
is an infix operator for fmap
List(1,2,3).flatMap(x => List(x, x))
// res: List(1, 1, 2, 2, 3, 3)
[1,2,3] >>= \x -> [x,x]
-- res: [1,1,2,2,3,3]