I use NonEmpty a lot and these are the functions I find useful:
-- | /O(n)/. Append an element to a list.
(|:) :: [a] -> a -> NonEmpty a
(|:) xs x = foldr cons (pure x) xs
-- | Append a list to a non-empty list.
appendl :: NonEmpty a -> [a] -> NonEmpty a
appendl (x :| xs) l = x :| (xs ++ l)
-- | Append a non-empty list to a list.
appendr :: [a] -> NonEmpty a -> NonEmpty a
appendr l nel = foldr cons nel l
There are certainly other useful functions for NonEmpty (e.g., the counterparts of many functions in Data.List.Extra), but I find these particularly useful since they obviate the need to use the partial fromList. So hopefully this is a reasonable starting point.
I use
NonEmpty
a lot and these are the functions I find useful:There are certainly other useful functions for
NonEmpty
(e.g., the counterparts of many functions inData.List.Extra
), but I find these particularly useful since they obviate the need to use the partialfromList
. So hopefully this is a reasonable starting point.