O(n). Return all the elements of a
NonEmpty list
except the last one element.
Actual type of this function is the following:
init :: NonEmpty a -> [a]
but it was given a more complex type to provide friendlier compile
time errors.
>>> init ('a' :| "bcde")
"abcd"
>>> init [0..5 :: Int]
...
... 'init' works with 'NonEmpty', not ordinary lists.
Possible fix:
Replace: [Int]
With: NonEmpty Int
...
However, you can use 'init' with the ordinary lists.
Apply 'viaNonEmpty' function from relude:
viaNonEmpty init (yourList)
Note, that this will return 'Maybe [Int]'
therefore it is a safe function unlike 'init' from the standard Prelude
...
>>> init (Just 'a')
...
... 'init' works with 'NonEmpty Char' lists
But given: Maybe Char
...