-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add functionality to construct products in applicative / monadic way #101
Conversation
joroKr21
commented
Sep 15, 2022
•
edited
Loading
edited
- TODO: Add tests
96568d2
to
c51430c
Compare
c51430c
to
23e7ce3
Compare
4b3c8af
to
5646fdd
Compare
48751fc
to
0c5f26e
Compare
value <- fieldMap.get(field).toRight(s"Missing field '$field';") | ||
parsed <- parser.parse(value, accum) | ||
yield parsed | ||
if accum then inst.constructA(parseField)(pure, map, ap) |
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.
I got so confused as to why constructA
and constructM
would be different for Either
and then realized you're doing naughty things with ap
😂
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.
Yeah, I didn't want to spend too much time defining Validated
so I just used an inconsistent Either
final def erasedConstructA[F[_]](f: Any => F[Any])(pure: Pure[F], map: MapF[F], ap: Ap[F]): F[Any] = | ||
traverseProduct(new ArrayProduct(is), (tc, _) => f(tc))(pure, map, ap) | ||
|
||
final def erasedConstructM[F[_]](f: Any => F[Any])(pure: Pure[F], map: MapF[F], tailRecM: TailRecM[F]): F[Any] = |
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 this just a stacksafe version of constructA
or is there some other difference that I've missed?
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.
constructA
is based on Applicative
:
- It can be parallel
- It cannot short circuit (evaluates for all fields)
- It is not stack safe (currently) - but it could be optimized if we build a tree instead of a list of
ap
constructM
is based on Monad
:
- It is always sequential
- It can short circuit
- It is stack safe
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.
cats.Applicative
actually has map2Eval
which can short circuit but that's too much complexity for Shapeless
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.
@TimWSpence here is a failed attempt to make traverse
and constructA
stack safe: #103
But it doesn't actually build a tree ...
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.
Sorry, just saw this. Will have a look!