Skip to content

Commit

Permalink
Move List.find_map to import
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
rgrinberg committed Nov 15, 2020
1 parent 73f7db8 commit 8bb896d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 8 additions & 0 deletions opium/src/import.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ module List = struct
| None :: l -> filter_opt l
| Some x :: l -> x :: filter_opt l
;;

let rec find_map ~f = function
| [] -> None
| x :: l ->
(match f x with
| Some _ as result -> result
| None -> find_map ~f l)
;;
end

module String = StringLabels
12 changes: 2 additions & 10 deletions opium/src/middlewares/middleware_router.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,8 @@ let add t ~route ~meth ~action =
(** finds matching endpoint and returns it with the parsed list of parameters *)
let matching_endpoint endpoints meth uri =
let endpoints = get endpoints meth in
let rec find_map ~f = function
| [] -> None
| x :: l ->
(match f x with
| Some _ as result -> result
| None -> find_map ~f l)
in
find_map
~f:(fun ep -> uri |> Route.match_url (fst ep) |> Option.map (fun p -> ep, p))
endpoints
List.find_map endpoints ~f:(fun ep ->
uri |> Route.match_url (fst ep) |> Option.map (fun p -> ep, p))
;;

module Env = struct
Expand Down

0 comments on commit 8bb896d

Please sign in to comment.