I am making an http request using OCaml. To construct headers I have ended up with the following working code
let body =
let headers = Header.init () in
let headers = Header.add headers "foo" "bar" in
let uri = Uri.of_string "https://www.example.com/" in
Client.get ~headers:headers uri >>= fun (resp, body) ->
(* rest of client code irrelevant *)
However, lines 2 and 3 offend me (perhaps as I am very new to OCaml).
So I thought something like this would work, and be less offensive to my delicate sensibilities.
let headers = Header.init |> Header.add "foo" "bar" in
However this fails to compile as the first arg for Header.add is expected to be of type Header.t and I provide a string. Is there a language feature to choose which args to partially apply? I have seen flip that can be found in Jane Street core and Batteries which would let me use the nicer syntax; however if I understand correctly this will flip all args and I will end up passing the value first instead of the key.
Is there any way to choose which arg to partially apply? For example in Scala we can produce a function using the 'placeholder' _;
val f1 = (v1: String, v2: String, v3: String) => 42
val f2 = f1("foo", _, "baz") // f2 is a String => Int
List("a", "b", "c").map(f1(_, "bar", "baz")) // this is fine.
Thanks for reading.
Client.get ~headers uriinstead ofClient.get ~headers:headers uri- ghilesZ