package ppx_yojson

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

Install

Dune Dependency

Authors

Maintainers

Sources

ppx_yojson-1.2.0.tbz
sha256=d12b59c88b8866d38a40d0e3eb3465727db35a19b27fdea739e9875628a10651
sha512=d3ec6e18e60eff1c3a7fbbadb852fbe2953f26735034c8aea494a7f1af3620a8d3a05e38d8ad7427871451e439fa359e1b96cf7a3ff936071e91e48a9fa4831f

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.