init -package:bytestring
Return all the elements of a list except the last one.
The list must be non-empty.
WARNING: This function is partial. Consider using
unsnoc
instead.
Examples
>>> init [1, 2, 3]
[1,2]
>>> init [1]
[]
>>> init []
*** Exception: Prelude.init: empty list
Extract everything except the last element of the stream.
O(1) Returns all but the last character of a
Text, which
must be non-empty. This is a partial function, consider using
unsnoc instead.
O(n/c) Returns all but the last character of a
Text,
which must be non-empty. This is a partial function, consider using
unsnoc instead.
O(1) Yield all but the last element without copying. The vector
may not be empty.
O(1) Yield all but the last element without copying. The vector
may not be empty.
Drop the last element of the mutable vector without making a copy. If
the vector is empty, an exception is thrown.
Drop the last element of the mutable vector without making a copy. If
the vector is empty, an exception is thrown.
O(1) Yield all but the last element without copying. The vector
may not be empty.
Drop the last element of the mutable vector without making a copy. If
the vector is empty, an exception is thrown.
O(1) Yield all but the last element without copying. The vector
may not be empty.
Drop the last element of the mutable vector without making a copy. If
the vector is empty, an exception is thrown.
O(1) Yield all but the last element without copying. The vector
may not be empty.
Drop the last element of the mutable vector without making a copy. If
the vector is empty, an exception is thrown.
Call
hc-pkg to initialise a package database at the location
{path}.
hc-pkg init {path}
Return all the elements of a list except the last one.
The list must be non-empty.
>>> init [1, 2, 3]
[1,2]
>>> init [1]
[]
>>> init []
*** Exception: Prelude.init: empty list
WARNING: This function is partial. You can use
reverse with
case-matching or
uncons instead.
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
...