Add list singleton function
Sometimes it is convenient to have a function to wrap an element in a list. There are many ways to do this already, but none of them are as clear as a separate monomorphic function.
pure: Polymorphic, works for any
pure @: Noisy, requires
(: ): Subjectively ugly.
(\x -> [x]): Syntactically noisy.
This Twitter thread includes some additional commentary: https://twitter.com/taylorfausak/status/1159264862247280640
I would like to add a
singleton function to
Data.List that mirrors the
singleton function for other containers: https://www.stackage.org/lts-14.0/hoogle?q=singleton
singleton :: a -> [a] singleton x = [x]
Other Haskell-like languages include this function: