package ppx_yojson

  1. Overview
  2. Docs
PPX extension for Yojson literals and patterns

Install

Dune Dependency

Authors

Maintainers

Sources

ppx_yojson-1.3.0.tbz
sha256=df1b4246969d6e1e2ff53c4c41a674c9653f214d93ad1421788ba55cf539266f
sha512=a4b5663ee2dec0c0fe0dc3e4f5ec59a1d23e057c1759c2433b45318c3a64f709e7e3ab91c98b9a4e1e5c9e3290a2772f5b7450ecf58f6280e52df033a60d877a

doc/src/ppx_yojson._lib/utils.ml.html

Source file utils.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
let remove ~idx l =
  let rec aux ~left ~right ~i =
    match right with
    | _ :: tl when i = idx -> List.rev_append left tl
    | hd :: tl -> aux ~left:(hd :: left) ~right:tl ~i:(i + 1)
    | [] -> l
  in
  aux ~left:[] ~right:l ~i:0

let rec permutations = function
  | [] -> [ [] ]
  | [ elm ] -> [ [ elm ] ]
  | l ->
      List.mapi
        (fun idx elm ->
          List.map (List.cons elm) (permutations @@ remove ~idx l))
        l
      |> List.flatten

let rewrite_field_name name =
  if name.[0] = '_' then String.(sub name 1 (length name - 1)) else name
OCaml

Innovation. Community. Security.