-- | Extract the first element of a list, which must be non-empty.
head :: HasCallStack => [a] -> a
head = \case
[] -> error "..."
x : _ -> x
Motivation: Universum is primarily designed to be used in business logic, if someone needs advanced and lightweight manipulation with lists, he better import Data.List or some library with special data structures as Universum provides far not all possible useful functions anyway.
Pros:
Easer to debug.
Cons:
Error messages will differ.
Slightly less performant (carrying call stack has its costs, some rewrite rules will probably get lost).
Attempt to import head both from our Unsafe module and Data.List module simultaneously will now fail, though this is minor as Unsafe module should be imported qualified.
For instance, have
Motivation:
Universum
is primarily designed to be used in business logic, if someone needs advanced and lightweight manipulation with lists, he better importData.List
or some library with special data structures asUniversum
provides far not all possible useful functions anyway.Pros:
Cons:
head
both from ourUnsafe
module andData.List
module simultaneously will now fail, though this is minor asUnsafe
module should be imported qualified.