-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any thoughts if this should just be an alias for Kleisli
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A third option is trait Lambda[F[_], Event, Result]
that may or may not extend Function2
😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying this out in #60.
...ustom-resource/src/main/scala/feral/lambda/cloudformation/CloudFormationCustomResource.scala
Outdated
Show resolved
Hide resolved
Co-authored-by: Brian P. Holt <bholt+github@planetholt.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
IOLambda
concept, with two goals:A lambda is re-imagined as:
And
IOLambda
now defines an abstract:This
handler
encapsulates the previously separateSetup
: all resource acquisition goes into building theLambda
once, and that is the "setup". ThatLambda
is then installed as the handler.From here, we have two axes on which we can do composition:
flatMap
ping 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.