f# - Use combinators to clean up mapJsonAsync in Suave.io -


in suave.io, there's function mapjson:

let mapjson (f: 'a -> 'b) =   request(fun r ->     f (fromjson r.rawform)      |> tojson     |> successful.ok      >=> writers.setmimetype "application/json") 

is there way make async version of using combinators? can write out hand follows

let mapjsonasync (f: 'a -> async<'b>) (ctx: httpcontext) =   async {     let! x = f(fromjson ctx.request.rawform)     let resp = successful.ok (tojson x) >>= writers.setmimetype "application/json"     return! resp ctx   } 

but nicer not have explicitly define ctx or intermediate values.

i not see way around that. last expression can simplified little.

let mapjsonasync (f: 'a -> async<'b>) =   fun (ctx : httpcontext) ->     async{       let! result = f (fromjson ctx.request.rawform)       return successful.ok (tojson result ) ctx >>= writers.setmimetype "application/json"     } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -