-
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
Add IO Monad #109
Add IO Monad #109
Conversation
Codecov Report
@@ Coverage Diff @@
## master #109 +/- ##
============================================
- Coverage 54.82% 52.77% -2.06%
- Complexity 177 183 +6
============================================
Files 77 83 +6
Lines 1098 1243 +145
Branches 169 180 +11
============================================
+ Hits 602 656 +54
- Misses 433 521 +88
- Partials 63 66 +3
Continue to review full report at Codecov.
|
Missing: most tests |
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.
review IOMonad, IOMonoid and IOSemigrup to use IO<A>
as parent generic type and returning type instead of HK<IO.F,A>
@@ -0,0 +1,14 @@ | |||
package katz | |||
|
|||
class IOMonoid<A>(val SM: Monoid<A>) : Monoid<HK<IO.F, 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.
i think you could use IO<A>
instead of HK definition here
package katz | ||
|
||
class IOMonoid<A>(val SM: Monoid<A>) : Monoid<HK<IO.F, A>> { | ||
override fun empty(): HK<IO.F, 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.
same here for returning type
|
||
fun <B> flatMap(f: (A) -> IO<B>): IO<B> = | ||
flatMapTotal( | ||
AndThen { a: 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.
it's necessary specify the Type here?
|
||
companion object { | ||
// Actually limited to 9223372036854775807 days, so unless you are very patient, it is unlimited ;-) | ||
val Infinite = Duration(amount = Long.MAX_VALUE, timeUnit = TimeUnit.DAYS) |
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 the constants naming style capitalized?
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.
Fixed!
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.
Looks great but we need to change those methods returning Option in the unsafe*
runners.
@@ -0,0 +1,70 @@ | |||
/** |
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.
We should have attribution in files like License or where they belong like we do in the typelevel cats case.
@@ -0,0 +1,11 @@ | |||
package katz | |||
|
|||
class IOSemigroup<A>(val SM: Semigroup<A>) : Semigroup<HK<IO.F, 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.
should this use default params for the registered instance value if not provided at instantiation?
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.
The companion object has invoke overloaded to provide a default value. n this case IO acts as a wrapper, and the SemiGroup depends mostly on the contents. We could have separate invokes for common types that are not globally registered like numbers and lists.
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.
makes sense
} | ||
} | ||
|
||
override fun unsafeRunTimedTotal(limit: Duration): Option<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.
I think returning Option
in any of the unsafe methods will be confusing to users. We should return the expected value and since those methods are already unsafe let any exceptions propagate if unfolding the Option returned a NoSuchElementException.
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.
The reason why this return Option is that None represents executing code that returns null. Errors still throw. I don't believe we should stop null-capable execution so we have to choose between returning Option or 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.
We've had a chat and decided on the API. unsafeRunTimedTotal returns Option, unsafeRun() returns A.
} | ||
} | ||
|
||
val Long.days: Duration |
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.
interesting way to provide duration out from any numeric types.
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.
It's copypasterino, check the license atop of the file :D
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.
package katz.effects.internal | ||
|
||
/** | ||
* Abandon all hope |
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.
Could you add some docs here about the purpose of this class ? I am trying to learn something here and that could be helpful :D
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.
Done in the branch that adds AndThen!
# Conflicts: # reports/baseline.xml
# Conflicts: # reports/baseline.xml
# Conflicts: # kategory/src/main/kotlin/kategory/instances/IdMonad.kt
Codecov Report
@@ Coverage Diff @@
## master #109 +/- ##
========================================
Coverage ? 55.2%
Complexity ? 212
========================================
Files ? 86
Lines ? 1317
Branches ? 179
========================================
Hits ? 727
Misses ? 519
Partials ? 71
Continue to review full report at Codecov.
|
Media resources should be managed from https://github.com/arrow-kt/arrow-media
This PR adds an implementation of IO based off Cats. It includes a Duration util for blocking operations.