-
Notifications
You must be signed in to change notification settings - Fork 0
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
custom Result #1
Conversation
} | ||
|
||
"should handle exception when mapping result success" { | ||
"should propagate exception when mapping result success" { | ||
val monoResult: SingleResult<String, SomeFailure> = "Some value".justSingleResult() | ||
val runtimeException = RuntimeException() | ||
|
||
monoResult.flatMapResult { if (true) throw runtimeException else Result.success("Some other value") } |
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.
if (true) throw runtimeException else Result.success("Some other value")
this condition is always true
. Why it was done this way? Btw. it's also duplicated in this test
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.
if(true) is here because I want an exception to be always thrown
else branch is so that the code compiles
@@ -34,8 +33,7 @@ internal class MonoResultKtTest : StringSpec() { | |||
|
|||
monoResult.flatMapResult { if (true) throw runtimeException else Result.success("Some other value") } |
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 comment here about always true
condition
@@ -0,0 +1,414 @@ | |||
//package com.github.kittinunf.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.
why this test is commented out?
//import org.junit.Test | ||
//import org.hamcrest.CoreMatchers.`is` as isEqualTo | ||
// | ||
//class ValidationTests { |
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.
why this test is commented out?
I spotted something interesting in main
it looks like a mix of your own branch with MIT license but referes to |
as I understand, it's just a copy from some point in time of Result and we don't want to just fork it and eventually introduce new changes from the original location? |
|
||
fun <V : Any, E : Exception> Result<V, E>.any(predicate: (V) -> Boolean): Boolean = try { | ||
when (this) { | ||
is Result.Success -> predicate(value) |
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.
here also we may spot an exception
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.
ah...nvm, its covered with try
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.
but that's the case, some try
s were removed here?
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 nicey but there are some comments to discuss
fun <V : Any, U : Any> Result<V, *>.fanout(other: () -> Result<U, *>): Result<Pair<V, U>, *> = | ||
flatMap { outer -> other().map { outer to it } } | ||
|
||
fun <V : Any, E : Exception> List<Result<V, E>>.lift(): Result<List<V>, E> = fold(Result.success(mutableListOf<V>()) as Result<MutableList<V>, E>) { acc, 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.
imo it should be named sequence
as in other FP libraries, I'd expect lift
to only wrap some value in container
false | ||
} | ||
|
||
fun <V : Any, U : Any> Result<V, *>.fanout(other: () -> Result<U, *>): Result<Pair<V, U>, *> = |
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'd name it zip
Codecov Report
@@ Coverage Diff @@
## master #1 +/- ##
============================================
- Coverage 85.31% 84.67% -0.65%
Complexity 18 18
============================================
Files 10 10
Lines 143 137 -6
Branches 14 14
============================================
- Hits 122 116 -6
Misses 19 19
Partials 2 2
Continue to review full report at Codecov.
|
No description provided.