package core_kernel
- Overview
- No Docs
You can search for identifiers within the package.
in-package search v0.2.0
Industrial strength alternative to OCaml's standard library
Install
Dune Dependency
Authors
Maintainers
Sources
core_kernel-v0.16.0.tar.gz
sha256=e37370bad978cfb71fdaf2b1a25ab1506b98ef0b91e0dbd189ffd9d853245ce2
doc/src/core_kernel.enum/enum.ml.html
Source file enum.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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
open! Base include Enum_intf module Single = struct module type S = Sexp_of type 'a t = (module S with type t = 'a) let command_friendly_name s = s |> String.tr ~target:'_' ~replacement:'-' |> String.lowercase |> String.filter ~f:(Char.( <> ) '\'') ;; let atom (type a) (m : a t) a = let module M = (val m) in match [%sexp_of: M.t] a with | Atom s -> s | List _ as sexp -> raise_s [%sexp "Enum.t expects atomic sexps.", (sexp : Sexp.t)] ;; let to_string_hum m a = command_friendly_name (atom m a) let check_field_name t a field = [%test_eq: string] (to_string_hum t a) (command_friendly_name (Field.name field)) ;; end type 'a t = (module S with type t = 'a) let to_string_hum (type a) ((module M) : a t) a = Single.to_string_hum (module M) a let check_field_name (type a) ((module M) : a t) a field = Single.check_field_name (module M) a field ;; let enum (type a) ((module M) : a t) = List.map M.all ~f:(fun a -> to_string_hum (module M) a, a) ;; let assert_alphabetic_order_exn here (type a) ((module M) : a t) = let as_strings = List.map M.all ~f:(Single.atom (module M)) in [%test_result: string list] ~here:[ here ] ~message:"This enumerable type is intended to be defined in alphabetic order" ~expect:(List.sort as_strings ~compare:String.compare) as_strings ;; module Rewrite_sexp_of (S : S) : S with type t = S.t = struct include S let sexp_of_t t = to_string_hum (module S) t |> Parsexp.Single.parse_string_exn end let arg_type (type t) ?case_sensitive ?key ?list_values_in_help (module S : S with type t = t) = Command.Arg_type.enumerated_sexpable ?key ?list_values_in_help ?case_sensitive (module Rewrite_sexp_of (S)) ;; module Make_param = struct type 'a t = { arg_type : 'a Command.Arg_type.t ; doc : string } let create ?case_sensitive ?key ?represent_choice_with ?list_values_in_help ~doc m = let doc = match represent_choice_with with | None -> " " ^ doc | Some represent_choice_with -> represent_choice_with ^ " " ^ doc in { arg_type = arg_type ?case_sensitive ?key ?list_values_in_help m; doc } ;; end type ('a, 'b) make_param = ?case_sensitive:bool -> ?represent_choice_with:string -> ?list_values_in_help:bool -> ?aliases:string list -> ?key:'a Univ_map.Multi.Key.t -> string -> doc:string -> 'a t -> 'b Command.Param.t let make_param ~f ?case_sensitive ?represent_choice_with ?list_values_in_help ?aliases ?key flag_name ~doc m = let { Make_param.arg_type; doc } = Make_param.create ?case_sensitive ?key ?represent_choice_with ?list_values_in_help ~doc m in Command.Param.flag ?aliases flag_name ~doc (f arg_type) ;; let make_param_optional_with_default_doc (type a) ~default ?case_sensitive ?represent_choice_with ?list_values_in_help ?aliases ?key flag_name ~doc (m : a t) = let { Make_param.arg_type; doc } = Make_param.create ?case_sensitive ?key ?represent_choice_with ?list_values_in_help ~doc m in Command.Param.flag_optional_with_default_doc ?aliases flag_name arg_type (fun default -> Sexp.Atom (to_string_hum (module (val m)) default)) ~default ~doc ;; let make_param_one_of_flags ?(if_nothing_chosen = Command.Param.If_nothing_chosen.Raise) ?aliases ~doc m = Command.Param.choose_one ~if_nothing_chosen (List.map (enum m) ~f:(fun (name, enum) -> let aliases = Option.map aliases ~f:(fun aliases -> aliases enum) in let doc = doc enum in Command.Param.flag ?aliases name (Command.Param.no_arg_some enum) ~doc)) ;; let make_param_optional_comma_separated ?allow_empty ?unique_values ?case_sensitive ?represent_choice_with ?list_values_in_help ?aliases ?key flag_name ~doc m = let open Command.Param in let options = enum m |> List.map ~f:fst |> List.sort ~compare:[%compare: string] |> String.concat ~sep:", " in make_param ?case_sensitive ?represent_choice_with ?list_values_in_help ?aliases ?key flag_name m ~f: (Fn.compose optional (Command.Arg_type.comma_separated ?allow_empty ?unique_values)) ~doc:[%string {|%{doc} (can be comma-separated values: %{options})|}] ;; module Make_of_string (M : S_to_string) = struct let to_string = M.to_string let of_string = let known_values = lazy (List.fold [%all: M.t] ~init:(Map.empty (module String)) ~f:(fun map t -> Map.set map ~key:(to_string t) ~data:t)) in fun s -> match Map.find (force known_values) s with | None -> let known_values = Map.keys (force known_values) in raise_s [%message "Unknown value." s (known_values : string list)] | Some t -> t ;; end module Make_stringable (M : S) = struct include Make_of_string (struct include M let to_string = to_string_hum (module M) end) end
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>