module Seq: BatSeqBasically you should use a sequence when you would prefer using a list or a lazy-list but constructing the whole list explicitly would explode your memory.
All functions returning a sequence operates in time and space O(1).
Note that if you want a ``consumable sequence'', you should prefer
using enumerations (from module BatEnum).
type'at =unit -> 'a node
type 'a node =
| |
Nil |
| |
Cons of |
include BatInterfaces.Mappable
val enum : 'a t -> 'a BatEnum.tenum s returns the enumeration of all element of s.
Since enumerations are consumable and sequence are not, it is
not possible to have the inverse operations, i.e. of_enum
val length : 'a t -> intval hd : 'a t -> 'aInvalid_argument if
the sequence is empty.val tl : 'a t -> 'a tInvalid_argument if the sequence is empty.val is_empty : 'a t -> boolis_empty e returns true if e does not contains any
element.val first : 'a t -> 'aBatSeq.hdval last : 'a t -> 'aInvalid_argument if
the sequence is empty.val at : 'a t -> int -> 'aat l n returns the n-th element of the sequence l or raise
Invalid_argument is the index is outside of l bounds.val append : 'a t -> 'a t -> 'a tappend s1 s2 returns the sequence which first returns all
elements of s1 then all elements of s2.val concat : 'a t t -> 'a tconcat s returns the sequence which returns all the elements
of all the elements of s, in the same order.val flatten : 'a t t -> 'a tBatSeq.concat.val nil : 'a tnil = fun () -> Nilval cons : 'a -> 'a t -> 'a tcons e s = fun () -> Cons(e, s)val make : int -> 'a -> 'a tmake n e returns the sequence of length n where all elements
are eval init : int -> (int -> 'a) -> 'a tinit n f returns the sequence returning the results of f 0,
f 1.... f (n-1). Raise Invalid_arg if n < 0.val iter : ('a -> unit) -> 'a t -> unititer f s applies f to all the elements of the sequence.val map : ('a -> 'b) -> 'a t -> 'b tmap f s returns the sequence where elements are elements of
s mapped with f.val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'afold_left f a (cons b1 (... bn)) is f (... (f (f a b1) b2) ...)
bn. Tail-recursive.val fold_right : ('a -> 'b -> 'b) -> 'a t -> 'b -> 'bfold_right f (cons a1 (... an)) b is f a1 (f a2 (... (f an b)
...)). Not tail-recursive.val reduce : ('a -> 'a -> 'a) -> 'a t -> 'areduce f (cons e s) is fold_left f e s.Invalid_argument on empty sequences.val max : 'a t -> 'amax s returns the largest value in s as judged by
Pervasives.compareval min : 'a t -> 'amin s returns the smallest value in s as judged by
Pervasives.compareval for_all : ('a -> bool) -> 'a t -> boolfor_all p (cons a1 (... an)) checks if all elements of the
given sequence satisfy the predicate p. That is, it returns
(p a1) && (p a2) && ... && (p an).val exists : ('a -> bool) -> 'a t -> boolexists p (cons a1 (... an)) checks if at least one element of
the sequence satisfies the predicate p. That is, it returns
(p a1) || (p a2) || ... || (p an).val mem : 'a -> 'a t -> boolmem a l is true if and only if a is equal to an element of
l.val find : ('a -> bool) -> 'a t -> 'a optionfind p s returns the first element of s such as p e
returns true, if any.val find_map : ('a -> 'b option) -> 'a t -> 'b optionfind_map p s finds the first element of s for which p e
returns Some r, if any.val filter : ('a -> bool) -> 'a t -> 'a tfilter p s returns the sequence of elements of s satisfying
p.val filter_map : ('a -> 'b option) -> 'a t -> 'b tfilter_map f s returns the sequence of elements filtered and
mapped by f.val assoc : 'a -> ('a * 'b) t -> 'b optionassoc a s returns the value associated with key a in the
sequence of pairs s.val take : int -> 'a t -> 'a ttake n s returns up to the n first elements from sequence
s, if available.val drop : int -> 'a t -> 'a tdrop n s returns s without the first n elements, or the
empty sequence if s have less than n elements.val take_while : ('a -> bool) -> 'a t -> 'a ttake_while f s returns the first elements of sequence s
which satisfy the predicate f.val drop_while : ('a -> bool) -> 'a t -> 'a tdrop_while f s returns the sequence s with the first
elements satisfying the predicate f dropped.val split : ('a * 'b) t -> 'a t * 'b tsplit s = (map fst s, map snd s)val combine : 'a t -> 'b t -> ('a * 'b) tval print : ?first:string ->
?last:string ->
?sep:string ->
('a BatInnerIO.output -> 'b -> unit) ->
'a BatInnerIO.output -> 'b t -> unitval sprint : ?first:string ->
?last:string ->
?sep:string -> ('a BatInnerIO.output -> 'b -> unit) -> 'b t -> stringval t_printer : 'a BatValue_printer.t -> 'a t BatValue_printer.tmodule Exceptionless:sig..end