Module Lwt_sequence
Contents
Instructions: Use this module in your project
In the IDE (CLion, Visual Studio Code, Xcode, etc.) you use for your DkSDK project:
Add the following to your project's
dependencies/CMakeLists.txt:DkSDKProject_DeclareAvailable(lwt CONSTRAINT "= 5.6.1" FINDLIBS lwt lwt.unix) DkSDKProject_MakeAvailable(lwt)Add the
Findlib::lwtlibrary to any desired targets insrc/*/CMakeLists.txt:target_link_libraries(YourPackage_YourLibraryName # ... existing libraries, if any ... Findlib::lwt)Click your IDE's
Buildbutton
Not using DkSDK?
FIRST, do one or all of the following:
Run:
opam install lwt.5.6.1Edit your
dune-projectand add:(package (name YourExistingPackage) (depends ; ... existing dependenices ... (lwt (>= 5.6.1))))Then run:
dune build *.opam # if this fails, run: dune buildEdit your
<package>.opamfile and add:depends: [ # ... existing dependencies ... "lwt" {>= "5.6.1"} ]Then run:
opam install . --deps-only
FINALLY, add the lwt library to any desired (library)and/or (executable) targets in your **/dune files:
(library
(name YourLibrary)
; ... existing library options ...
(libraries
; ... existing libraries ...
lwt))
(executable
(name YourExecutable)
; ... existing executable options ...
(libraries
; ... existing libraries ...
lwt))A sequence is an object holding a list of elements which support the following operations:
-
adding an element to the left or the right in time and space O(1)
-
taking an element from the left or the right in time and space O(1)
-
removing a previously added element from a sequence in time and space O(1)
-
removing an element while the sequence is being transversed.
-
deprecated
This module should be an internal implementation detail of Lwt, and may be removed from the API at some point in the future. Use package
lwt-dllistinstead.
type``'a t
Type of a sequence holding values of type 'a
type``'a node
Type of a node holding one value of type 'a in a sequence
Operation on nodes
valget :'anode->'a
Returns the contents of a node
valset :'anode->'a->unit
Change the contents of a node
valremove :'anode->unit
Removes a node from the sequence it is part of. It does nothing if the node has already been removed.
Operations on sequence
valcreate : ``unit->'at
create () creates a new empty sequence
valclear :'at->unit
Removes all nodes from the given sequence. The nodes are not actually mutated to note their removal. Only the sequence's pointers are updated.
valis_empty :'at->bool
Returns true iff the given sequence is empty
vallength :'at->int
Returns the number of elements in the given sequence. This is a O(n)
operation where n is the number of elements in the sequence.
exceptionEmpty
Exception raised by take_l and take_r and when the sequence is empty
valtake_l :'at->'a
take_l x s remove and returns the leftmost element of s
-
raises Empty
if the sequence is empty
valtake_r :'at->'a
take_r x s remove and returns the rightmost element of s
-
raises Empty
if the sequence is empty
valtake_opt_l :'at->'aoption
take_opt_l x s remove and returns Some x where x is the leftmost
element of s or None if s is empty
valtake_opt_r :'at->'aoption
take_opt_r x s remove and returns Some x where x is the rightmost
element of s or None if s is empty
transfer_l s1 s2 removes all elements of s1 and add them at the left
of s2. This operation runs in constant time and space.
transfer_r s1 s2 removes all elements of s1 and add them at the
right of s2. This operation runs in constant time and space.
Sequence iterators
Note: it is OK to remove a node while traversing a sequence
valiter_l : ``('a->unit)``->'at->unit
iter_l f s applies f on all elements of s starting from the left
valiter_r : ``('a->unit)``->'at->unit
iter_r f s applies f on all elements of s starting from the right
iter_node_l f s applies f on all nodes of s starting from the left
iter_node_r f s applies f on all nodes of s starting from the
right
valfold_l : ``('a->'b->'b)``->'at->'b->'b
fold_l f s is:
fold_l f s x = f en (... (f e2 (f e1 x)))where e1, e2, ..., en are the elements of s
valfold_r : ``('a->'b->'b)``->'at->'b->'b
fold_r f s is:
fold_r f s x = f e1 (f e2 (... (f en x)))where e1, e2, ..., en are the elements of s
find_node_opt_l f s returns Some x, where x is the first node of
s starting from the left that satisfies f or None if none exists.
find_node_opt_r f s returns Some x, where x is the first node of
s starting from the right that satisfies f or None if none exists.
find_node_l f s returns the first node of s starting from the left
that satisfies f or raises Not_found if none exists.
find_node_r f s returns the first node of s starting from the right
that satisfies f or raises Not_found if none exists.
