Composable, effect-agnostic lambdas#51
Conversation
| package feral | ||
|
|
||
| package object lambda { | ||
| type Lambda[F[_], Event, Result] = (Event, Context[F]) => F[Option[Result]] |
There was a problem hiding this comment.
Any thoughts if this should just be an alias for Kleisli?
There was a problem hiding this comment.
Is there any advantage to making it so?
One very minor downside: I think making it Kleisli would mean, when running it, we'd generally have to wrap the event and context in two sets of parens, since it would expect a tuple instead of being a Function2.
There was a problem hiding this comment.
Kleisli is enriched with lots of nice methods that are also (more likely to be) stack-safe.
http://typelevel.org/cats/api/cats/data/Kleisli.html
since it would expect a tuple instead of being a Function2
Yep, exactly my reasoning for avoiding this.
Very similar discussion in http4s/http4s#4846.
There was a problem hiding this comment.
Given the http4s experience and the fact that it sounds like they're going to move away from the Kleisli alias, I'm inclined to think we probably shouldn't introduce it here. But I don't have a super strong feeling either way.
There was a problem hiding this comment.
A third option is trait Lambda[F[_], Event, Result] that may or may not extend Function2 😅
There was a problem hiding this comment.
A fourth option 😆 http4s will be rewriting its middlewares to use MTL-style Ask/Local instead of directly using Kleisli. Since we are taking a middleware-oriented approach here, perhaps we should do the same.
http4s/http4s#4758
Co-authored-by: Brian P. Holt <bholt+github@planetholt.com>
djspiewak
left a comment
There was a problem hiding this comment.
Couple thoughts here…
What's the advantage to Lambda itself being parametric in F? I see the advantage with Context and I think that's a good change, but the parametricity doesn't seem all that helpful in Lambda's case.
Unrelatedly… The new Setup encoding seems really strange to me, unless I'm misunderstanding what it is meant to be doing. Is this orthogonal to the Resource support idea?
Not really sure how to answer this. Why is http4s
Hmm, after re-encoding the old way seemed really strange to me :P Not sure what you mean by orthogonal. Instead of |
|
Superseded by #60. |
This was #45, before we started experimenting on that branch 😁
This re-works the original
IOLambdaconcept, with two goals:A lambda is re-imagined as:
And
IOLambdanow defines an abstract:This
handlerencapsulates the previously separateSetup: all resource acquisition goes into building theLambdaonce, and that is the "setup". ThatLambdais then installed as the handler.From here, we have two axes on which we can do composition:
flatMapping resources:@bpholt and I have put this to good use in #45 and #50 to create a Natchez tracing middleware for lambda and I'm pretty confident that this is the right approach.