I've been using ((:[]) <$> xs)
but if there is a more clear way I would love to use it.
edit: so many good answers guys! I don't think I can accept one because they are all good.
I believe map return
or map pure
are good enough.
Maybe this?
map (\x -> [x]) xs
Yours can work on any functor I think so this would be more idomatic for just lists.
The split package provides a (Data.List.Split.)chunksOf function whose name is, IMO, more meaningful than the various map solutions (even if they are more idiomatic.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With