init package:base

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.
The inits function returns all initial segments of the argument, shortest first. inits is semantically equivalent to map reverse . scanl (flip (:)) [], but under the hood uses a queue to amortize costs of reverse.

Laziness

Note that inits has the following strictness property: inits (xs ++ _|_) = inits xs ++ _|_ In particular, inits _|_ = [] : _|_

Examples

>>> inits "abc"
["","a","ab","abc"]
>>> inits []
[[]]
inits is productive on infinite lists:
>>> take 5 $ inits [1..]
[[],[1],[1,2],[1,2,3],[1,2,3,4]]
The inits1 function returns all non-empty initial segments of the argument, shortest first.

Laziness

Note that inits1 has the following strictness property: inits1 (xs ++ _|_) = inits1 xs ++ _|_ In particular, inits1 _|_ = _|_

Examples

>>> inits1 "abc"
['a' :| "",'a' :| "b",'a' :| "bc"]
>>> inits1 []
[]
inits1 is productive on infinite lists:
>>> take 3 $ inits1 [1..]
[1 :| [],1 :| [2],1 :| [2,3]]
The inits function takes a stream xs and returns all the finite prefixes of xs, starting with the shortest. The result is NonEmpty because the result always contains the empty list as the first element.
inits [1,2,3] == [] :| [[1], [1,2], [1,2,3]]
inits [1] == [] :| [[1]]
inits [] == [] :| []
The inits1 function takes a NonEmpty stream xs and returns all the NonEmpty finite prefixes of xs, starting with the shortest.
inits1 (1 :| [2,3]) == (1 :| []) :| [1 :| [2], 1 :| [2,3]]
inits1 (1 :| []) == (1 :| []) :| []
Total CPU time used by the init phase @since base-4.12.0.0
Total elapsed time used by the init phase @since base-4.12.0.0
Pi: Punctuation, Initial quote
True if the argument is an IEEE infinity or negative infinity
The thread is blocked on an MVar, but there are no other references to the MVar so it can't ever continue.
The thread is waiting to retry an STM transaction, but there are no other references to any TVars involved, so it can't ever continue.
The FiniteBits class denotes types with a finite, fixed number of bits.
Return the number of bits in the type of the argument. The actual value of the argument is ignored. Moreover, finiteBitSize is total, in contrast to the deprecated bitSize function it replaces.
finiteBitSize = bitSize
bitSizeMaybe = Just . finiteBitSize