package bonsai

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file map_incr.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
open! Core_kernel
open! Import
open Incremental.Let_syntax
open Component

module T = struct
  type ('input, 'model, 'action, 'result, 'incr, 'event) unpacked +=
    | C :
        { t : ('input, 'model, 'action, 'r1, 'incr, 'event) unpacked
        ; f : ('r1, 'incr) Incremental.t -> ('r2, 'incr) Incremental.t
        }
        -> ('input, 'model, 'action, 'r2, 'incr, 'event) unpacked

  let extension_constructor = [%extension_constructor C]

  let sexp_of_unpacked t =
    match t with
    | C { t; f = _ } -> [%sexp Map_incr (t : unpacked)]
    | _ -> assert false
  ;;

  let eval (type i m a r incr event) : (i, m, a, r, incr, event) eval_type =
    fun ~input ~old_model ~model ~inject ~action_type_id ~environment ~incr_state t ->
      match t with
      | C { t; f } ->
        let snapshot =
          eval_ext
            ~input
            ~old_model
            ~model
            ~inject
            ~action_type_id
            ~environment
            ~incr_state
            t
        in
        let result = snapshot >>| Snapshot.result |> f in
        let apply_action = snapshot >>| Snapshot.apply_action in
        let%map result = result
        and apply_action = apply_action in
        Snapshot.create ~result ~apply_action
      | _ -> assert false
  ;;

  let map_incr (Packed.T { unpacked; action_type_id; model }) ~f =
    Packed.T { unpacked = C { t = unpacked; f }; action_type_id; model }
  ;;

  let visit (Packed.T { unpacked; action_type_id; model }) visitor =
    match unpacked with
    | C { t; f } ->
      let visited = visit_ext (T { unpacked = t; action_type_id; model }) visitor in
      visitor.visit (map_incr visited ~f)
    | _ -> assert false
  ;;
end

include T

let () = Component.define (module T)
OCaml

Innovation. Community. Security.