Do monad transformers apply to getting JSON from services?

前端 未结 2 1680
醉酒成梦
醉酒成梦 2021-02-07 06:26

I have a Play! 2 for Scala application that needs to retrieve some data in JSON format from an external service.

The Play! framework allows to make HTTP requests asynchr

2条回答
  •  借酒劲吻你
    2021-02-07 06:38

    -- removed --

    edit:

    Okay, you can simply use the scalaz.OptionT here:

    val x = optionT(Promise { /* api call */ some("""{ "foo": "bar" }""") })
    val mapped = x.map(Json.parse).run // run return the resulting Promise[Option[T]]
    

提交回复
热议问题