package range

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

Range library for making easy folding on a sequence of integers Copyright (C) 2018,2019 Aldrik KLEBER

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

type t
type elt = Base.int

t type correspond to an integer range value

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 : (elt -> Base.bool) -> t -> 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 fold : ('a -> elt -> 'a) -> 'a -> t -> '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 -> elt -> 'a) -> 'a -> t -> '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 : (elt -> Base.unit) -> t -> 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 : elt -> elt -> 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 : (elt -> elt) -> t -> t

apply f to elements contained in a Range.t value

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

  • parameter f

    function to apply to the content of a range value

  • parameter r

    range to modify

  • returns

    updated range

OCaml

Innovation. Community. Security.