package lascar
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=343190b9c765655e787758db86a82818404dda18b4d2806283b4bde3ced91d26
sha512=2b6534ac438d574228d127b3b4e2cfec17b8b95e95124297c8da351caf34de2bb4ec8a31028a1470ba7f42aa932257293d021140a5a1c2642d1a60a8123d00a0
doc/lascar.utils/Utils/ListExt/index.html
Module Utils.ListExt
Source
Extension to the Stdlib.List
module
fold_lefti f a [b1; ...; bn]
is f (... (f 1 (f 0 a b1) b2) ...) bn
.
fold_righti f [a1; ...; an] b
is f a1 (f (n-2) a2 (... (f (n-1) an b) ...))
.
Transform a list of triplets into a triplet of lists.
Transform a triplet of lists into a list of triplets.
to_string f sep [x1;...;xn]
returns f x1 ^ sep ^ f x2 ^ sep ^ ... ^ sep ^ f xn
or the empty string if the list is empty
make f n1 n2
returns [f n1; ..., f n2]
if n2>=n1
or the empty list if n2<n1
index_of e l
returns the index of the first occurence of e
in list l
, starting at 0.
flat_map f [x1;...,xn]
is f x1 @ f x2 @ ... @ f xn
inter l1 l2
returns the intersection of the lists l1
and l2
union l1 l2
returns the union of the lists l1
and l2
merge p l1 l2
merges lists l1
and l2
using comparison function cmp
(default: Pervasives.compare). For example, merge [1;3;8] [2;5;6;10] = [1;2;3;5;5;8;10]
.
prod f l1 l2
computes the "product" of lists l1
and l2
, i.e. the list obtained by applying f
to each possible pair of elements of l1
and l2
.
cart_prod
is a specialized version of prod
in which f x y = (x,y)
prod3
(resp. cart_prod3
) are generalisations of prod
(resp. cart_prod2
) to three input lists
gen_cart_prod
computes the n-ary cartesian product of lists.
filter_map p f l
is a short-cut for List.map f (List.filter p l)
iter_sep f g l
is like List.iter f l
but calls function g
between each call to function f
.
iter_fst f [x1;x2;...xn]
is f true x1; f false x2; ...; f false xn
remove e l
is a short-cut for List.filter (fun e' -> e <> e') l)
power_set l
computes the "power set" of l
, i.e. the list of all lists composed of elements of l
. The length of the result is 2^n
, where n
is the length of l
. Example: power [1;2;3]
is [[];[1];[2];[3];[1;2];[1;3];[2;3];[1;2;3]]
power n l
computes the list of all lists of length n
made of elements of l
. The length of the result is m^n
, where m
is the length of l
. Example : power 2 [1;2;3]
is [[1;1];[2;1];[3;1];[1;2];[2;2];[3;2];[1;3];[2;3];[3;3]]
assoc
(resp. mem_assoc
) is a variant of Stdlib.List.assoc
(resp. Stdlib.List.mem_assoc
) in which the comparison function used for comparing keys can be passed as an optional argument. By default, Pervasive.compare
is used.
val update_assoc :
?cmp:('k -> 'k -> int) ->
('v -> 'a -> 'v) ->
'k ->
'a ->
('k * 'v) list ->
('k * 'v) list
partition [(x1,y1);...;(xn;yn)]
returns the list [k1,ys1; ...;km,ysm]
where k1
,...,km
are all the distinct values occuring in [x1;...;xn]
and ysi
the list of values yj
paired with ki
in the input list. For example partition [(1,"a");(3,"b");(1,"c");(3,"d")]
is [3,["d";"b"];1,["b";"a"]]
.
scatter h l
returns an array a
in which a.(i)
is the list of all elements x
of l
such that h x = i
. The length of the array is computed from the maximum value of h
on l
. Example: scatter String.length ["a";"bc";"de";"fghi"]
is [|[];["a"];["bc;de"];[];["fghi"]|]
. As for assoc
and mem_assoc
, the comparison function can be specified with the optional argument cmp
.
Higher-order parser for lists