Haskell has a built-in function that creates a list from a single element?

Looking for a built-in function that will do the following:

mklist x = [x]

The advantage is that I can use it in the composition to create a list of one item. Understand that (copy 1) is available, but is there a more direct function? It would be useful in such situations:

["Alice", "Bob", "Charlie"] >>= mklist . ("Hello " ++)
+5
source share
1 answer

Monadic return :

return x

Or:

(:[]) x

These are fewer characters, but more use of the shift keys, so it can be harder to type.

+11
source

All Articles