tail
Warning: This is a partial function, it throws an error on empty
lists. Replace it with drop 1, or use pattern matching or
uncons instead. Consider refactoring to use
Data.List.NonEmpty.
Extract the possibly-empty tail of the stream.
O(1) Extract the elements after the head of a ByteString, which
must be non-empty. An exception will be thrown in the case of an empty
ByteString.
This is a partial function, consider using
uncons instead.
O(1) Extract the elements after the head of a ByteString, which
must be non-empty.
This is a partial function, consider using
uncons instead.
O(n) Extract the elements after the head of a ShortByteString,
which must be non-empty. An exception will be thrown in the case of an
empty ShortByteString.
This is a partial function, consider using
uncons instead.
Note: copies the entire byte array
O(1) Returns all characters after the head of a
Text,
which must be non-empty. This is a partial function, consider using
uncons instead.
Extract the elements after the head of a list, which
must be non-empty.
>>> tail [1, 2, 3]
[2,3]
>>> tail [1]
[]
>>> tail []
*** Exception: Prelude.tail: empty list
WARNING: This function is partial. You can use case-matching or
uncons instead.
tail xs is a list of the elements in
xs excluding the first element. If
xs is
empty, an
error is raised.
<math>(
length (toList xs)).
tail obeys the law:
tail xs = tail (toList xs)
tail xs is a
DList of the elements in
xs excluding the first element.
<math>(
1).
tail obeys the law:
toList (tail xs) = tail (toNonEmpty xs)
O(1). Return all the elements of a
NonEmpty list after
the head element.
Actual type of this function is the following:
tail :: NonEmpty a -> [a]
but it was given a more complex type to provide friendlier compile
time errors.
>>> tail ('a' :| "bcde")
"bcde"
>>> tail [0..5 :: Int]
...
... 'tail' works with 'NonEmpty', not ordinary lists.
Possible fix:
Replace: [Int]
With: NonEmpty Int
...
However, you can use 'tail' with the ordinary lists.
Apply 'viaNonEmpty' function from relude:
viaNonEmpty tail (yourList)
Note, that this will return 'Maybe [Int]'
therefore it is a safe function unlike 'tail' from the standard Prelude
...
>>> tail (Just 'a')
...
... 'tail' works with 'NonEmpty Char' lists
But given: Maybe Char
...
Extract the elements after the head of a list, which
must be non-empty.
To disable the warning about partiality put
{-# OPTIONS_GHC
-Wno-x-partial -Wno-unrecognised-warning-flags #-} at the top of
the file. To disable it throughout a package put the same options into
ghc-options section of Cabal file. To disable it in GHCi put
:set -Wno-x-partial -Wno-unrecognised-warning-flags into
~/.ghci config file. See also the
migration guide.
Examples
>>> tail [1, 2, 3]
[2,3]
>>> tail [1]
[]
>>> tail []
*** Exception: Prelude.tail: empty list
O(1) Extract the elements after the head of a ByteString, which
must be non-empty.
O(1) Extract the elements after the head of a ByteString, which
must be non-empty. An exception will be thrown in the case of an empty
ByteString.
Extract the elements after the head of a list, which
must be non-empty.
O(1) Returns all characters after the head of a
Text,
which must be non-empty. Subject to fusion.
O(1) Yield all but the first element without copying. The
vector may not be empty.
O(1) Yield all but the first element without copying. The
vector may not be empty.
O(1) Yield all but the first element without copying. The
vector may not be empty.
O(1) Yield all but the first element without copying. The
vector may not be empty.
Safe version of
tailEx, only working on non-nullable
sequences.