Skip to content

Commit

Permalink
Change query functions to use t-first style
Browse files Browse the repository at this point in the history
  • Loading branch information
aantron committed Feb 11, 2022
1 parent 940b07a commit 9bec26f
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion example/w-query/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This very simple example accesses a value in the query string with
```ocaml
let () =
Dream.run (fun request ->
match Dream.query "echo" request with
match Dream.query request "echo" with
| None ->
Dream.html "Use ?echo=foo to give a message to echo!"
| Some message ->
Expand Down
2 changes: 1 addition & 1 deletion example/w-query/query.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let () =
Dream.run (fun request ->
match Dream.query "echo" request with
match Dream.query request "echo" with
| None ->
Dream.html "Use ?echo=foo to give a message to echo!"
| Some message ->
Expand Down
6 changes: 2 additions & 4 deletions src/dream.mli
Original file line number Diff line number Diff line change
Expand Up @@ -432,16 +432,14 @@ https://github.com/aantron/dream/issues
(** Replaces the version. See {!Dream.version}. *)
(**/**)

(* TODO Convert query string functions to the new t-first style. *)

val query : string -> request -> string option
val query : request -> string -> string option
(** First query parameter with the given name. See
{{:https://tools.ietf.org/html/rfc3986#section-3.4} RFC 3986 §3.4} and
example
{{:https://github.com/aantron/dream/tree/master/example/w-query#files}
[w-query]}. *)

val queries : string -> request -> string list
val queries : request -> string -> string list
(** All query parameters with the given name. *)

val all_queries : request -> (string * string) list
Expand Down
4 changes: 2 additions & 2 deletions src/server/query.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ let all_queries request =
|> snd
|> Formats.from_form_urlencoded

let query name request =
let query request name =
List.assoc_opt name (all_queries request)

let queries name request =
let queries request name =
all_queries request
|> List.fold_left (fun accumulator (name', value) ->
if name' = name then
Expand Down
6 changes: 2 additions & 4 deletions test/expect/pure/formats/query/query.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@


let query name string =
Dream.request ~target:("/?" ^ string) ""
|> Dream.query name
Dream.query (Dream.request ~target:("/?" ^ string) "") name
|> function
| Some value -> Printf.printf "%S\n" value
| None -> print_endline "None"
Expand Down Expand Up @@ -36,8 +35,7 @@ let%expect_test _ =


let queries name string =
Dream.request ~target:("/?" ^ string) ""
|> Dream.queries name
Dream.queries (Dream.request ~target:("/?" ^ string) "") name
|> List.map (Printf.sprintf "%S")
|> String.concat " "
|> Printf.printf "[%s]\n"
Expand Down

0 comments on commit 9bec26f

Please sign in to comment.