Skip to content
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

Merged
merged 5 commits into from
Dec 7, 2019
Merged

custom Result #1

merged 5 commits into from
Dec 7, 2019

Conversation

krzykrucz
Copy link
Collaborator

No description provided.

}

"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") }

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

Copy link
Collaborator Author

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") }

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

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 {

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?

@jakubiec
Copy link

I spotted something interesting in main build.gradle.kts, namely below snippet:

    configure<BintrayExtension> {
        user = findProperty("BINTRAY_USER") as? String
        key = findProperty("BINTRAY_KEY") as? String
        setPublications(project.name)
        publish = true
        pkg.apply {
            repo = "maven"
            name = "base-types-kt"
            desc = "The modelling for success/failure of operations in Kotlin"
            userOrg = "kittinunf"
            websiteUrl = "https://github.com/krzykrucz/base-types-kt"
            vcsUrl = "https://github.com/krzykrucz/base-types-kt"
            setLicenses("MIT")
            version.apply {
                name = artifactPublish
            }
        }
    }

it looks like a mix of your own branch with MIT license but referes to kittinunf userOrg. Shouldn't it refer to VirtusLab repo and organisation?

@jakubiec
Copy link

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)

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

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

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 trys were removed here?

Copy link

@jakubiec jakubiec left a 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 ->
Copy link
Contributor

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>, *> =
Copy link
Contributor

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-io
Copy link

codecov-io commented Dec 7, 2019

Codecov Report

Merging #1 into master will decrease coverage by 0.64%.
The diff coverage is 100%.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ Complexity Δ
...m/virtuslab/basetypes/result/reactor/MonoResult.kt 91.66% <100%> (-0.93%) 0 <0> (ø)
.../virtuslab/basetypes/result/rxjava/SingleResult.kt 82.14% <100%> (-1.73%) 0 <0> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c7af734...f3833a2. Read the comment docs.

@krzykrucz krzykrucz merged commit 91614c0 into master Dec 7, 2019
@krzykrucz krzykrucz deleted the result branch March 12, 2020 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants