package spotlib

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Spotlib.SpotStreamSource

Lazy list or Stream

Type
Sourcetype 'a desc =
  1. | Cons of 'a * 'a desc lazy_t
  2. | Null
Sourcetype 'a t = 'a desc lazy_t
Constructors
Sourceval null : 'a t

a constant null

Sourceval cons : 'a -> 'a t -> 'a t
Sourceval (^^) : 'a -> 'a t -> 'a t

same as cons

Sourceval singleton : 'a -> 'a t
Sourceval create : ('st -> ('a * 'st) option) -> 'st -> 'a t

Pure functional creator

Deconstructors
Sourceval hd : 'a t -> 'a
Sourceval tl : 'a t -> 'a t
Sourceval peek : 'a t -> ('a * 'a t) option

You can use match with lazy pattern instead of peek

Sourceval is_null : 'a t -> bool

null check

Sourceval nth : 'a t -> int -> 'a
Sourceval length : 'a t -> int
Conversions between the eager list
Sourceval to_list : 'a t -> 'a list

Conversion from a lazy stream to a strict list. Do not use against inifinite streams.

Sourceval of_list : 'a list -> 'a t

Conversion from a strict list to a lazy stream. The conversion itself is done strictly: the result has no reference to the original list

Misc functions
Sourceval take : int -> 'a t -> 'a t

take n t takes the first n elements of t. Lazy.

Sourceval init : 'a t -> 'a t

init t returns the same list t but without its final element.

Sourceval rev : 'a t -> 'a t
Sourceval filter : ('a -> bool) -> 'a t -> 'a t
Sourceval filter_map : ('a -> 'b option) -> 'a t -> 'b t
Sourceval concat : 'a t t -> 'a t
Sourceval mem : 'a -> 'a t -> bool

Membership. Never terminates over inifinite streams.

Sourceval iter : ('a -> unit) -> 'a t -> unit

Iteration. Never terminates over inifinite streams.

Sourceval map : ('a -> 'b) -> 'a t -> 'b t

Map

Sourceval fold_left : ('a Lazy.t -> 'b -> 'a Lazy.t) -> 'a Lazy.t -> 'b t -> 'a Lazy.t

Folding left

Sourceval fold_left1 : ('a Lazy.t -> 'a Lazy.t -> 'a Lazy.t) -> 'a Lazy.t t -> 'a Lazy.t

fold_left1 f (x^^xs) = fold_left f x xs fold_left1 f null raises an exception.

Sourceval fold_left' : ('a -> 'b -> 'b) -> 'b -> 'a t -> 'b

Folding left, strict version. Never terminates over inifinite streams. Tail recursive.

Sourceval fold_right : ('a -> 'b lazy_t -> 'b lazy_t) -> 'a t -> 'b lazy_t -> 'b lazy_t

fold_right f t init. Folding right. Not tail recursive. If laziness is required, it is the responsibility of f.

Sourceval fold_right1 : ('a -> 'a lazy_t -> 'a lazy_t) -> 'a t -> 'a lazy_t -> 'a lazy_t

fold_right1 f (append xs (singleton x)) = fold_right f xs x fold_right1 f null raises an exception. If laziness is required, it is the responsibility of f.

Sourceval append : 'a t -> 'a t -> 'a t

Append. Lazy.

Sourceval intercalate : 'a t -> 'a t t -> 'a t

Haskell's intercalate

Sourceval intersparse : 'a -> 'a t -> 'a t

Haskell's intersparse

Sourceval split_at : int -> 'a t -> 'a list * 'a t

Haskell's splitAt. Prefix is forced.

Sourceval split_at' : int -> 'a t -> 'a t * 'a t

Haskell's splitAt. Prefix is lazy.

Inpure hacks
Sourceval rev_between : 'a t -> 'a t -> 'a list
Sourceval between : 'a t -> 'a t -> 'a list

Get elements between two points of the *same* stream.

The first argument of rev_between and between must point the former element of the stream than the second argument. Otherwise, the behaviour of rev_between and between are not specified: a wrong result or memory exhaustion by an infinite loop.

Monadic interface

include Monad.T with type 'a t := 'a t
Sourceval return : 'a -> 'a t
Sourceval bind : 'a t -> ('a -> 'b t) -> 'b t
Sourceval fmap : ('a -> 'b) -> 'a t -> 'b t

fmap in Haskell

Sourceval liftM : ('a -> 'b) -> 'a t -> 'b t

synonym of fmap

Sourceval fmap2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t

fmap2 in Haskell

Sourceval liftM2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t

synonym of fmap2

Sourceval void : 'a t -> unit t
Sourceval seq : 'a t list -> 'a list t

sequence in Haskell. Not tail recursive.

Sourceval seq_ : unit t list -> unit t

sequence_ in Haskell. Not tail recursive.

Sourceval mapM : ('a -> 'b t) -> 'a list -> 'b list t

Not tail recursive by default

Sourceval mapM_ : ('a -> unit t) -> 'a list -> unit t

Not tail recursive by default

Sourceval iteri : (int -> 'a -> unit t) -> 'a list -> unit t

Iteration with index starting from 0. Not tail recursive by default

Sourceval for_ : int -> int -> (int -> unit t) -> unit t

for like iteration. Not tail recursive by default

Sourceval join : 'a t t -> 'a t
OCaml

Innovation. Community. Security.