package range

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

Range module provide a type for handling the description of an integer sequence described by a start value and a stop value. This module provide functions to fold, filter and map this range.

The main goal is to : * provide a split capacity in order to make life easy for distributed processing. * avoid the use of list or lazy list when the only need is to sequence a range of integer.

  • author Aldrik KLEBER <contact@aldrik.net>
type t

t type correspond to an integer range value

type elt = Base.Int.t
module Number : sig ... end

'a number type is an integer with constraints *

include Base.Equal.S with type t := t
val equal : t Base.Equal.equal
include Base.Stringable.S with type t := t
val of_string : string -> t
val to_string : t -> string
val from : elt -> elt -> t

from start_value stop_value : will create a t value representing the range described by the two values given in parameter.

  • parameter start

    Integer representating the starting value of the range

  • parameter stop

    Integer representing the last value of the range

  • returns

    Range.t type which value defined by start and stop parameters

val filter : t -> f:(elt -> Base.bool) -> t

filter f range : will create a new Range.t value using predicate function f. This modifies the behaviour of iter or fold function in order to apply only to values that satisfies the predicate.

  • parameter ~f

    the predicate is attached to the range value, the predicate must respect the signature int -> bool

  • parameter range

    range to be filtered, if the range provided has already a filter, the new range value will merge the two filters.

  • returns

    new Range.t value with a new filter added.

val reset : t -> t

remove all map and filter effects from a range.

  • parameter old

    Range.t value

  • returns

    new Range.t value from parameter without modifiers.

val is_natural : t -> Base.bool

is filtered predicate

test if a Range.t value contain a filter or map function transforming data.

  • parameter Range.t

    value to test

  • returns

    test true if there is a filter false otherwise

val length : t -> Base.Int.t

length range_value : return the number of elements contained in rang_value

  • parameter range_value

    : range_value of type t

  • returns

    Int.t with the number of elements

val fold : 'a -> t -> f:('a -> elt -> 'a) -> 'a

fold the equivalent of List.fold_left applied to integer range_record explore all the values contained in the range value applying f to the accumulator and the current element read by fold. If a filter was associated to the range value, only element validated by the predicate f will be passed to the function.

  • parameter f

    function aggregating the accumulator to the current value.

  • parameter acc

    initial value of the accumulator

  • parameter range

    explored range value

  • returns

    value of the accumulator after reading all elements

val fold_right : 'a -> t -> f:('a -> elt -> 'a) -> 'a

fold_right explore all the values contained in the range value, in reverse order, starting by the last value to the first one, applying f to the accumulator and the current element read by fold. If a filter was associated to the range value, only element validated by the predicate f will be passed to the function.

  • parameter f

    function aggregating the accumulator to the current value.

  • parameter acc

    initial value of the accumulator

  • parameter range

    explored range value

  • returns

    value of the accumulator after reading all elements

val iter : t -> f:(elt -> Base.unit) -> Base.unit

iter apply a function with side effect on all values of the range. This function support filtering.

  • parameter f

    function receiving an integer and returning unit

  • parameter range

    value

  • returns

    unit

val split : [ `Greater_than_zero ] Number.t -> [ `Greater_than_zero ] Number.t -> t -> t Base.list

split a range value into a list of smaller range, useful for batching in parallel processing.

  • parameter minimal

    size of a range

  • parameter count

    number of subranges contained in the list.

  • parameter range

    value to split

  • returns

    list of ranges with a size of minimal or greater, the list having count elements max.

val contain : elt -> t -> Base.bool

contain function to test if an integer value is contained in a Range.t values

  • parameter element

    to be tested

  • parameter reference

    range value

  • returns

    true if element is contained in reference

val cross : t -> t -> t Base.Option.t

new Range.t value representing the common value between two Range.t values.

  • parameter a

    Range.t value

  • parameter b

    Range.t value

  • returns

    option value with Range.t option type value defined by the common values, None if it is impossible to find common values.

val cross_exn : t -> t -> t

Same as cross function with exception for error handling.

val join : t -> t -> t Base.Option.t

Join to generate a new Range.t value contained both a and b

  • parameter a

    Range.t value

  • parameter b

    Range.t value

  • returns

    Range.t option value containing both a and b. If a and b are disjoint, they can't be joinded so None is returned.

val join_exn : t -> t -> t

Same as join with exception for error handling

val map : t -> f:(elt -> elt) -> t

apply f to elements contained in a Range.t value

This feature uses a delayed application of f. Like for filters, f is stacked on previous filter or map functions.

  • parameter f

    function applied to range contents

  • parameter r

    range to modify

  • returns

    updated range

OCaml

Innovation. Community. Security.