Suave.io: using pathScan and request together
Asked Answered
B

1

6

I'm just getting up and running with Suave.io. I'm sure this will become clearer as I dig more into Applicatives - but from a high level I can't see how to write a pathScan rule that applies the request applicative too. All examples I'm found only do one or the other. In both cases they are applied to a function taking arguments - so presumably the arguments would be combined somehow too.

Bankbook answered 28/7, 2015 at 9:16 Comment(0)
S
10

Both pathScan and request take a function that produces a web part, so they cannot be nicely chained using >>=. Instead, you can nest one inside the other (I think the order does not really matter here):

pathScan "/some/%d" (fun num ->
  request (fun r -> 
    OK(sprintf "%d - %A" num r.url)))
Skittle answered 3/8, 2015 at 11:16 Comment(1)
Thanks. As is typical I arrived at the same conclusion just after prompting you on twitter! I don't know how I missed this the first time around. Seems obvious now.Bankbook

© 2022 - 2024 — McMap. All rights reserved.