package gapi-ocaml

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

Module GapiLensSource

Functional lenses.

Based on F# implementation in FSharpx (see src/FSharpx.Core/Lens.fs for the original implementation)

Sourcetype ('a, 'b) t = {
  1. get : 'a -> 'b;
    (*

    Functional getter

    *)
  2. set : 'b -> 'a -> 'a;
    (*

    Functional setter

    *)
}

Lens type definition

Sourceval modify : ('a, 'b) t -> ('b -> 'b) -> 'a -> 'a

Updates a value through a lens

Combinators

Sourceval compose : ('a, 'b) t -> ('c, 'a) t -> ('c, 'b) t

Sequentially composes two lenses

Sourceval pair : ('a, 'b) t -> ('c, 'd) t -> ('a * 'c, 'b * 'd) t

Pairs two lenses

Sourceval cond : ('a -> bool) -> ('a, 'b) t -> ('a, 'b) t -> ('a, 'b) t

Selects a lens checking a predicate.

cond pred lensTrue lensFalse: pred is applied to source. If true, lensTrue is selected. If false, lensFalse is selected.

State monad integration

Sourceval get_state : ('a, 'b) t -> 'a -> 'b * 'a

Gets a value from the state monad.

Sourceval put_state : ('a, 'b) t -> 'b -> 'a -> unit * 'a

Puts a value in the state monad.

Sourceval modify_state : ('a, 'b) t -> ('b -> 'b) -> 'a -> unit * 'a

Modifies a value in the state monad.

Stock lenses

Sourceval ignore : ('a, unit) t

Trivial lens

Sourceval id : ('a, 'a) t

Identity lens

Sourceval first : ('a * 'b, 'a) t

Gets/sets the first element in a pair

Sourceval second : ('a * 'b, 'b) t

Gets/sets the second element in a pair

Sourceval head : ('a list, 'a) t

Gets/sets the first element in a list

Sourceval tail : ('a list, 'a list) t

Gets/sets the tail of a list

Sourceval for_hash : 'a -> (('a, 'b) Hashtbl.t, 'b option) t

Lens for a particular key in a hashtable

Sourceval for_assoc : 'a -> (('a * 'b) list, 'b option) t

Lens for a particular key in an associative list

Sourceval for_array : int -> ('a array, 'a) t

Lens for a particular position in an array

Sourceval for_list : int -> ('a list, 'a) t

Lens for a particular position in a list

Sourceval option_get : ('a option, 'a) t

Lens for extracting the value from an option type (same as Option.get)

List combinators

Sourceval list_map : ('a, 'b) t -> ('a list, 'b list) t

Creates a lens that maps the given lens in a list

Isomorphism

Sourceval xmap : ('a -> 'b) -> ('b -> 'a) -> ('c, 'a) t -> ('c, 'b) t

Applies an isomorphism to the value viewed through a lens

Sourcemodule Infix : sig ... end

Infix operators

Sourcemodule StateInfix : sig ... end

Infix operators for the state monad

OCaml

Innovation. Community. Security.