package vdom

  1. Overview
  2. Docs
type arg_value =
  1. | StringArg of string
  2. | BoolArg of bool
  3. | FloatArg of float
  4. | IntArg of int
type _ t =
  1. | Field : string * 'msg t -> 'msg t
  2. | Method : string * arg_value list * 'msg t -> 'msg t
  3. | Bind : ('a -> 'msg t) * 'a t -> 'msg t
  4. | Const : 'msg -> 'msg t
  5. | Factor : ('a -> 'msg t) -> ('a -> ('msg, string) Stdlib.Result.t) t
  6. | String : string t
  7. | Int : int t
  8. | Float : float t
  9. | Bool : bool t
  10. | Object : js_object t
  11. | List : 'a t -> 'a list t
  12. | Fail : string -> 'msg t
  13. | Try : 'a t -> 'a option t
    (*

    The type of JavaScript object "structural" parsers. It allows to access the fields of JS objects and cast them to OCaml values.

    *)
val field : string -> 'a t -> 'a t

field s d accesses field s and applies decoder d to it. Deeper sub-fields can also be accessed by giving the full list of field names separated by dots.

val method_ : string -> arg_value list -> 'a t -> 'a t

method_ s l q calls method s with arguments l and applies d to the result.

val app : ('a -> 'b) t -> 'a t -> 'b t

Monadic applicative operation

val bind : ('a -> 'b t) -> 'a t -> 'b t

Monadic binding operation

val const : 'a -> 'a t

const x is a decoder that always returns x on any JS object

val return : 'a -> 'a t

return x is a decoder that always returns x on any JS object

val factor : ('a -> 'b t) -> ('a -> ('b, string) Stdlib.Result.t) t

factor f creates a decoder which returns a function which finishes applying the decoder returned by f with a given argument

val map : ('a -> 'b) -> 'a t -> 'b t

Monadic mapping operation

val map2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t

Maps the results of 2 decoders

val pair : 'a t -> 'b t -> ('a * 'b) t

Combine the results of 2 decoders to a pair

val fail : string -> 'a t

fail msg is a decoder which always fails with message msg

val try_ : 'a t -> 'a option t

try_ d is a decoder which returns None if d fails

val string : string t

Decode a JS string to an OCaml string

val int : int t

Decode a JS number to an OCaml integer

val float : float t

Decode a JS number to an OCaml float

val bool : bool t

Decode a JS boolean to an OCaml boolean

val unit : unit t

This decoder always returns ()

val object_ : js_object t

Decode a JS object to an OCaml representation

val list : 'a t -> 'a list t

list d decodes a JS array to an OCaml list, applying the decoder d to each element

val let* : 'a t -> ('a -> 'b t) -> 'b t
val let+ : 'a t -> ('a -> 'b) -> 'b t
val and+ : 'a t -> 'b t -> ('a * 'b) t
OCaml

Innovation. Community. Security.