The group function takes a stream and returns a list of
streams such that flattening the resulting list is equal to the
argument. Moreover, each stream in the resulting list
contains only equal elements, and consecutive equal elements
of the input end up in the same stream of the output list.
For example, in list notation:
Example1 expression
>>> group "Mississippi"["M", "i", "ss", "i", "ss", "i", "pp", "i"]
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.
insert x xs inserts x into the last position in xs where it
is still less than or equal to the next element. In particular, if the
list is sorted beforehand, the result will also be sorted.
The nub function removes duplicate elements from a list. In
particular, it keeps only the first occurrence of each element.
(The name nub means 'essence'.)
It is a special case of nubBy, which allows the programmer to
supply their own inequality test.
The partition function takes a predicate p and a stream
xs, and returns a pair of lists. The first list corresponds to the
elements of xs for which p holds; the second corresponds to the
elements of xs for which p does not hold.
'partition' p xs = ('filter' p xs, 'filter' (not . p) xs)
The tails function takes a stream xs and returns all the
suffixes of xs, starting with the longest. The result is NonEmpty
because the result always contains the empty list as the last element.
unfold produces a new stream by repeatedly applying the unfolding
function to the seed value to produce an element of type b and a new
seed value. When the unfolding function returns Nothing instead of
a new seed value, the stream ends.
Return the union of two non-empty lists. Duplicates, and elements of the
first list, are removed from the the second list, but if the first list
contains duplicates, so will the result.
Use compareLengthxsn as a safer and faster alternative
to compare (lengthxs) n. Similarly, it's better
to write compareLength xs 10 == LT instead of length xs < 10.
While length would force and traverse
the entire spine of xs (which could even diverge if xs is infinite),
compareLength traverses at most n elements to determine its result.