package ppx_yojson

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

Install

Dune Dependency

Authors

Maintainers

Sources

ppx_yojson-1.1.0.tbz
sha256=cf33d358237bdddceec22bdb67cfc6d7a311bfcd18ec60b743426796bad92547
sha512=38414025ad0495fe5e6ac049e9b2a96c557bc358af556c56a41c8e8e2da4badc1f8db98257f2f435711089e4799f95de17de23264114dafc37a4162357f596c4

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
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
OCaml

Innovation. Community. Security.