package devkit

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

Module Devkit_core.ActionSource

miscellaneous

Sourceval period : int -> (int -> unit) -> unit -> unit

period p f

  • returns

    a function pf such that pf () = f i when i mod p = 0, and () otherwise.

Sourceval timely : float -> ?first:float -> ('a -> unit) -> 'a -> unit

timely p f

  • parameter first

    the earliest time f x must be executed (now + p by default).

  • returns

    a function pf such that pf x = f x if the last execution of pf x was done more than p seconds ago, or () otherwise.

Sourceval timely_counter : float -> (int -> unit) -> unit -> unit

Combination of the above, see the code for more info.

Enum utilities

Sourceval uniq : ('a -> 'b) -> 'a Enum.t -> 'a Enum.t

uniq f e

  • returns

    enum that will not contain two values x and x' such that f x = f x'.

Sourceval all_uniq : ('a -> 'b) -> 'a Enum.t -> bool

all_uniq f e

  • returns

    true iff there is no two values x and x' in e such that f x = f x'.

Sourceval chunk_e : int -> 'a Enum.t -> 'a Enum.t Enum.t

chunk_e n e splits enum e into chunks of n elements each (except the last which can be shorter). NB the order in result is not specified

List utilities

Sourceval list_min : ?cmp:('a -> 'a -> int) -> 'a list -> 'a

find the minimum element in the list

  • parameter cmp

    compare function, default Stdlib.compare

  • raises Empty_list

    when list is empty

Sourceval list_uniq : ('a -> 'b) -> 'a list -> 'a list

list_uniq f l

  • returns

    copy of l that will not contain two values x and x' such that f x = f x'.

Sourceval list_sorted_uniq : ('a -> 'a -> bool) -> 'a list -> 'a list

list_sorted_uniq eq_f l

  • returns

    l without consecutive elements x, x' such that eq_f x = eq_f x'.

Sourceval list_random_exn : ?state:Random.State.t -> 'a list -> 'a

Get a random element from a list.

Sourceval list_random : ?state:Random.State.t -> 'a list -> 'a option
Sourceval slice : int -> int -> 'a list -> 'a list

extract sublist from a list, e.g. slice 1 3 [0;1;2;3;4] will return [1;2;3].

Partitioning a list into chunks

Sourceval chunk : int -> 'a list -> 'a list list

chunk n l splits list l into chunks of n elements each (except the last which can be shorter). NB the order in result is not specified FIXME?

Sourceval distribute : int -> 'a list -> 'a list array

distribute n l splits l into n chunks, does not preserve the order of the elements.

Sourceval undistribute : 'a list array -> 'a list
Sourceval partition : int -> 'a list -> 'a list array
  • deprecated use Action.distribute
Sourceval unpartition : 'a list array -> 'a list
  • deprecated use Action.undistribute
Sourceval stable_partition : int -> 'a list -> 'a list list

stable_partition l n splits l into n chunks, preserves the order of the elements.

Sourceval stable_unpartition : 'a list list -> 'a list

Array utilities

Sourceval array_random_exn : ?state:Random.State.t -> 'a array -> 'a
Sourceval array_random : ?state:Random.State.t -> 'a array -> 'a option
Sourceval array_rfindi : ('a -> bool) -> 'a array -> int

array_rfindi p a

  • returns

    index of first element matching p when iterating a in reverse.

Sourceval array_rfind : ('a -> bool) -> 'a array -> 'a

array_rfind p a

  • returns

    value index of first element matching p when iterating a in reverse.

Sourceval array_iter_rev : ('a -> unit) -> 'a array -> unit

array_iter_rev f a calls f on each elements of a in reverse order.

Sourceval shuffle : ?state:Random.State.t -> 'a array -> unit

shuffle ?state a shuffles an array, giving a uniform random distribution.

  • parameter state

    random state to use (default: global Random state)

Sourceval binary_search' : 'a array -> ('a -> 'b -> int) -> 'b -> 'a option

array must be sorted

Sourceval chunk_a : int -> 'a array -> 'a array list

chunk_a n a splits array a into chunks of n elements each (except the last which can be shorter), preserving the order of elements, i.e. reverse operation is Array.concat

DynArray utilities

Sourceval quick_sort : 'a DynArray.t -> ?start:int -> ?n:int -> ('a -> 'a -> int) -> unit

Hashtbl utilities

Sourceval hashtbl_find : ('a, 'b) Hashtbl.t -> (unit -> 'b) -> 'a -> 'b

hashtbl_find ht f_default k associates f_default () to k in ht, if no previous association exists.

  • returns

    Hashtbl.find ht k if k is associated with an element in ht, or f_default () otherwise.

Gc / Memory utilities

Memory format parsing/pretty-printing

Sourceval parse_bytes_unit : string -> int

Parse memory size specification, accepts: MB KB 1MB 20gb

Sourceval show_bytes_unit : int -> string

Pretty-print memory size in a way that can be parsed back by parse_bytes_unit

Pretty-printing

Sourceval bytes_of_words : int -> int
Sourceval bytes_of_words_f : float -> float
Sourceval bytes_string : int -> string

short human-readable display for memory measures

Sourceval bytes_string_i64 : int64 -> string
Sourceval bytes_string_f : float -> string
Sourceval caml_words : int -> string
Sourceval caml_words_f : float -> string
Sourceval gc_diff : Gc.stat -> Gc.stat -> string

string describing gc current settings.

Sourceval gc_show : string -> ('a -> 'b) -> 'a -> 'b
Sourceval gc_settings : unit -> string

File IO

Sourceval count_bytes_to : int64 ref -> 'a IO.output -> int64 IO.output

Counting bytes. Not closing underlying io.

Sourceval count_bytes : 'a IO.output -> int64 IO.output
Sourceval io_copy : IO.input -> 'a IO.output -> unit

Copy all data from input to output

Sourceval io_null : unit IO.output

/dev/null -like

Extracting lines from a file.

Sourceval file_lines_exn : string -> string list
Sourceval file_lines : string -> string list
Sourceval make_config_lines : string list -> string list

read lines from file skipping empty lines and comments (lines starting with '#')

Sourceval config_lines_exn : string -> string list
Sourceval config_lines : string -> string list

Time utilities

Sourceclass timer_start : Time.t -> object ... end

Basic timer. Also allows recording a sequence of interesting times from the given start point. Can serialize recorded events to json (useful for Logstash events)

Sourceclass timer : object ... end

Convenience wrapper to start timer_start with Time.now()

Sourceval uptime : timer

Timer running from the start of the program execution.

Sourceval speed : int -> float -> float

Log or time execution of a function

Sourceval log : ?name:string -> ('a -> unit) -> 'a -> unit
Sourceval log_do : ?name:string -> (unit -> unit) -> unit
Sourceval perform : ?name:string -> ('a -> unit) -> 'a -> bool

Comparison

Sourceval compare_by : ('a -> 'b) -> 'a -> 'a -> int
Sourceval compare2 : ('a -> 'b -> int) -> ('c -> 'd -> int) -> ('a * 'c) -> ('b * 'd) -> int
Sourceval compare2_by : ('a -> 'b) -> ('c -> 'd) -> ('a * 'c) -> ('a * 'c) -> int
Sourceval compare_fst : ('a -> 'b -> 'c) -> ('a * 'd) -> ('b * 'e) -> 'c

Benchmarking functions

Sourceval bench : ?compact:(unit -> unit) -> int -> (unit -> 'a) -> string
Sourceval run_bench : ?compact:(unit -> unit) -> int -> (string * (unit -> 'a)) list -> unit

Command-line arguments

Sourceval args : string list

Does not contains Sys.argv.(0).

Misc.

Sourceval shell_sequence : string list -> string list

name01 name02 name09 name10 name11 -> name0{1..2} name{09..11}

Sourceval hexdump : string -> string
Sourcetype ewma = (float -> unit) * (unit -> float)

Exponential Weighted Moving Average (smooth) 0.05 < alpha < 0.15 (dynamic)

Sourceval ewma : float -> ewma

ewma alpha

  • returns

    f_store, f_get such that f_store is used to add a value to the EWMA and f_get returns the current EWMA including all the value already stored.

Sourceval random_bytes : ?state:Random.State.t -> int -> string

generates a string of n random bytes.

Sourceval random_ascii : ?state:Random.State.t -> int -> string

generates a string of n random ascii chars.

OCaml

Innovation. Community. Security.