package ppx_deriving_yojson

  1. Overview
  2. Docs
JSON codec generator for OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

ppx_deriving_yojson-3.7.0.tar.gz
md5=456be82acb16bbf6be12ab01f9dfaa94
sha512=6aa8b3a6e60afd1ce68995bad6776c975b3640303b2049233e661c46300abea1f48916d4e876412de49f35744f31b99c29736e2bb974e1b4a494b0932bbd6e80

doc/src/ppx_deriving_yojson.runtime/ppx_deriving_yojson_runtime.ml.html

Source file ppx_deriving_yojson_runtime.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
include Ppx_deriving_runtime

let (>>=) x f =
  match x with Result.Ok x -> f x | (Result.Error _) as x -> x

let (>|=) x f =
  x >>= fun x -> Result.Ok (f x)

let rec map_bind f acc xs =
  match xs with
  | x :: xs ->
    (* equivalent to [f x >>= fun x -> map_bind f (x :: acc) xs],
       but do not use [(>>=)] to keep [map_bind] tail-recursive
       under js-of-ocaml *)
    (match f x with
     | ((Result.Error _) as err) -> err
     | Result.Ok x -> map_bind f (x :: acc) xs)
  | [] -> Result.Ok (List.rev acc)

type 'a error_or = ('a, string) Result.result

(** [safe_map f l] returns the same value as [List.map f l], but
    computes it tail-recursively so that large list lengths don't
    cause a stack overflow *)
let safe_map f l = List.rev (List.rev_map f l)
OCaml

Innovation. Community. Security.