aboutsummaryrefslogtreecommitdiff
path: root/motus/js/updateProposition.ml
blob: ab10db33bf3c00d109ccf3076ce4d896868f191a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
(** Update the current propositions when the user change a value in one of the
    field.
 *)

open StdLabels

type t =
  { position : int
  ; letter : Jstr.t
  ; validity : State.letter_validity
  }

let process { position; letter; validity } state =
  let current_prop =
    List.mapi state.State.current_prop ~f:(fun pos' content ->
        if position <> pos'
        then content
        else if Jstr.is_empty letter
        then None
        else Some (Jstr.uppercased letter, validity) )
  in
  FieldList.set_with_props current_prop state.fields state.rules;

  { state with current_prop }