Source file prism.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
(* Copyright (c) 2026, Cargocut and the Pidgin developers.
   All rights reserved.

   SPDX-License-Identifier: BSD-3-Clause *)

type 'a t =
  { conv : 'a Repr.conv
  ; check : 'a Check.t
  }

let make ~conv ~check = { conv; check }
let conv { conv; _ } = conv
let check { check; _ } = check

let invmap f g { conv; check } =
  { check = (fun x -> x |> check |> Result.map f)
  ; conv = (fun x -> x |> g |> conv)
  }
;;

let refine f g { conv; check } =
  { check = (fun x -> Result.bind (check x) f)
  ; conv = (fun x -> x |> g |> conv)
  }
;;