Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions otherlibs/stdune/src/list.ml
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,11 @@ let rec partition_three xs ~f =
| `Middle y -> xs, y :: ys, zs
| `Right z -> xs, ys, z :: zs)
;;

module Assoc = struct
let rec find_exn xs x ~equal =
match xs with
| [] -> raise Not_found
| (x', y) :: xs -> if equal x x' then y else find_exn xs x ~equal
;;
end
4 changes: 4 additions & 0 deletions otherlibs/stdune/src/list.mli
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,7 @@ val to_seq : 'a t -> 'a Seq.t
(** [list_intersperse t ~sep] returns [t] with [sep] inserted between each pair
of consecutive values. *)
val intersperse : 'a t -> sep:'a -> 'a t

module Assoc : sig
val find_exn : ('a * 'b) list -> 'a -> equal:('a -> 'a -> bool) -> 'b
end
6 changes: 3 additions & 3 deletions src/dune_sexp/decoder.ml
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,9 @@ and find_cstr
: type a. (string * a t) list -> Loc.t -> string -> values context -> values -> a
=
fun cstrs loc name ctx values ->
match List.assoc cstrs name with
| Some t -> result ctx (eval t ctx values)
| None ->
match List.Assoc.find_exn cstrs name ~equal:String.equal with
| t -> result ctx (eval t ctx values)
| exception Not_found ->
User_error.raise
~loc
~hints:(User_message.did_you_mean name ~candidates:(List.map cstrs ~f:fst))
Expand Down
Loading