Looking for a built-in function that will do the following:
mklist x = [x]
The benefit is that I can use it in a composition to create a list of one element. Understand that (replicate 1) is available but is there a more direct function? Would be useful in situations like this:
["Alice", "Bob", "Charlie"] >>= mklist . ("Hello " ++)
In Haskell, lists are a homogenous data structure. It stores several elements of the same type. That means that we can have a list of integers or a list of characters but we can't have a list that has a few integers and then a few characters.
If show is ok to print your elements, you can use putStr ( unlines $ map show [(1,"A"),(2,"B"),(3,"C"),(4,"D")]) but you can replace show by any funtion that'll take your custom type and return a string.
Finding / searching 0 will result in 1 . (Related: head xs returns the first element of the list.) (Related: last xs returns the last element of the list.)
Monadic return:
return x
Or:
(:[]) x
It's less characters, but more shift-key usage, so might be harder to type.
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