seq package:rio
The value of seq a b is bottom if a is bottom, and
otherwise equal to b. In other words, it evaluates the first
argument a to weak head normal form (WHNF). seq is
usually introduced to improve performance by avoiding unneeded
laziness.
A note on evaluation order: the expression seq a b does
not guarantee that a will be evaluated before
b. The only guarantee given by seq is that the both
a and b will be evaluated before seq
returns a value. In particular, this means that b may be
evaluated before a. If you need to guarantee a specific order
of evaluation, you must use the function pseq from the
"parallel" package.
General-purpose finite sequences.
Seq. Import as:
import qualified RIO.Seq as Seq
Evaluate each monadic action in the structure from left to right, and
collect the results. For a version that ignores the results see
sequence_.
Evaluate each action in the structure from left to right, and collect
the results. For a version that ignores the results see
sequenceA_.
Evaluate each action in the structure from left to right, and ignore
the results. For a version that doesn't ignore the results see
sequenceA.
Evaluate each monadic action in the structure from left to right, and
ignore the results. For a version that doesn't ignore the results see
sequence.
As of base 4.8.0.0,
sequence_ is just
sequenceA_,
specialized to
Monad.
Evaluate each action and collect the results
Evaluate each action and discard the results
Evaluate each action and collect the results
Evaluate each action and discard the results
The
isSubsequenceOf function takes two lists and returns
True if all the elements of the first list occur, in order, in
the second. The elements do not have to occur consecutively.
isSubsequenceOf x y is equivalent to
elem x
(subsequences y).
Examples
>>> isSubsequenceOf "GHC" "The Glorious Haskell Compiler"
True
>>> isSubsequenceOf ['a','d'..'z'] ['a'..'z']
True
>>> isSubsequenceOf [1..10] [10,9..0]
False
The
subsequences function returns the list of all subsequences
of the argument.
>>> subsequences "abc"
["","a","b","ab","c","ac","bc","abc"]
Sequences all the actions in a structure, building a new structure
with the same shape using the results of the actions. For a version
that ignores the results, see
bisequence_.
bisequence ≡ bitraverse id id
Evaluate each action in the structure from left to right, and ignore
the results. For a version that doesn't ignore the results, see
bisequence.
deepseq: fully evaluates the first argument, before returning
the second.
The name
deepseq is used to illustrate the relationship to
seq: where
seq is shallow in the sense that it only
evaluates the top level of its argument,
deepseq traverses the
entire data structure evaluating it completely.
deepseq can be useful for forcing pending exceptions,
eradicating space leaks, or forcing lazy I/O to happen. It is also
useful in conjunction with parallel Strategies (see the
parallel package).
There is no guarantee about the ordering of evaluation. The
implementation may evaluate the components of the structure in any
order or in parallel. To impose an actual order on evaluation, use
pseq from
Control.Parallel in the
parallel
package.
Evaluate
a as far as storing it in a vector would and yield
b. The
v a argument only fixes the type and is not
touched. The method is only used for optimisation purposes. Thus, it
is safe for instances of
Vector to evaluate
a less
than it would be when stored in a vector although this might result in
suboptimal code.
elemseq v x y = (singleton x `asTypeOf` v) `seq` y
Default defintion:
a is not evaluated at all