inits

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 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 [] == [] :| []
O(n) Returns all initial segments of the given ByteString, shortest first.
Returns all initial segments of the given ByteString, shortest first.
O(n) Return all initial segments of the given Text, shortest first.
O(n²) Return all initial segments of the given Text, shortest first.
Returns a sequence of all prefixes of this sequence, shortest first. For example,
inits (fromList "abc") = fromList [fromList "", fromList "a", fromList "ab", fromList "abc"]
Evaluating the <math>th prefix takes <math>, but evaluating every prefix in the sequence takes <math> due to sharing.
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 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 :| []) :| []
O(n) Returns all initial segments of the given ByteString, shortest first.
Returns all initial segments of the given ByteString, shortest first.
O(n) Return all initial segments of the given Text, shortest first.
O(n²) Return all initial segments of the given Text, shortest first.
Initialize StdGen using system entropy (i.e. /dev/urandom) when it is available, while falling back on using system time as the seed.
Initialise Simple optimiser configuration from DynFlags
Initialize STG pretty-printing options from DynFlags
Initialize STG pretty-printing options from DynFlags
Initialize STG pretty-printing options from DynFlags
Initialize StgToJS settings from DynFlags