-
Notifications
You must be signed in to change notification settings - Fork 454
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
Create StateT type #25
Conversation
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.
Excellent, let's replace eval with run. And let's provide runA, runS and run to get just A, just the State or both accordingly
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.
Apply the changes requested by @raulraja and you will have my approved too
fc35894
to
5859d3b
Compare
Codecov Report
@@ Coverage Diff @@
## master #25 +/- ##
============================================
- Coverage 54.82% 53.46% -1.37%
- Complexity 177 187 +10
============================================
Files 77 80 +3
Lines 1098 1154 +56
Branches 169 169
============================================
+ Hits 602 617 +15
- Misses 433 474 +41
Partials 63 63
Continue to review full report at Codecov.
|
PR updated! :) |
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.
Update State class to HKT and use Tupled class instead of Pair
* to returning the result of type A, the function | ||
* returns a new S value, which is the updated state. | ||
*/ | ||
class State<S, out A>(val runF: (S) -> Pair<S, A>) { |
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.
please use Tuple2 instead of Pair
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.
make it implement HK2<State.F,S,A>
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.
AFAIK, StateT is who has to support HKT, right? This State is using Identity as Monad Environment, isn't?
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.
About Tuple2, I will change it :)
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.
Raul's comment was very clear 😄
I will try to implement StateT
💪
Now that we have |
fun runS(s: S): S = run(s).a | ||
|
||
fun <B> map(f: (A) -> B): State<S, B> { | ||
return State { s1 -> |
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.
you can remove this return by using fun <B> map(f: (A) -> B) = State<S, B> { ... }
syntax
@arturogutierrez take a look at how |
I will gonna update this PR soon |
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.
Can you please add the Monad instances? It should be just evaluating the parameter and calling the methods in the object.
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.
LGTM for shipping. I have never had to overwrite map2 and map2Eval, is there a reason for this? It'd be great to have tests for them.
* 0.11.0/bio (#1975) * BIO - Part 1 (#1851) * Add E param * Fix imports & types * Add RaiseError case * Refactor IO name * [BIO]: include `E` into IOFrame & IORunLoop (#1859) * Rewrite IOFrame * Update IORunLoop & fix resulting combinators * Move public code to IO.kt * Refactor Right to Success * IO: IOConnection & IOBracket (#1870) * Update ForwardCancelable * Update IOBracket * Remove KindConnection and refactor into IOConnection * IO Concurrency combinators & Green Build (#1892) * BIO - Part 1 (#1851) * Add E param * Fix imports & types * Add RaiseError case * Refactor IO name * [BIO]: include `E` into IOFrame & IORunLoop (#1859) * Rewrite IOFrame * Update IORunLoop & fix resulting combinators * Move public code to IO.kt * Refactor Right to Success * IO: IOConnection & IOBracket (#1870) * Update ForwardCancelable * Update IOBracket * Remove KindConnection and refactor into IOConnection * Rewrite UnsafePromise * Rewrite ParMap2 * Update IOParMap3 * Update IORacePair * Update IORaceTriple * Fix tests * Fix KIO benchmarks * Fix imports Ank * Fix IOExample * Fix unused imports * Fix imports benchmarks * Fix arrow-integrations-retrofit-adapter * Fix FpToTheMax & typeclasses example * KtLintFormat * Fix IOTest * Fix more tests * Fix merge conflicts * KtLintFormat * Fix MaybeK bracket and use it for QueueTest * Throw proper exception in impossible cases * Revert removing runAsync * Fix build * KtLintFormat * Update version * After releasing 0.10.5: just considering one wip version (#26) Co-authored-by: Simon Vergauwen <[email protected]> Co-authored-by: Simon Vergauwen <[email protected]> Co-authored-by: raulraja <[email protected]>
Fixes #14
Super basic example of State Monad: