MarioAriasC / funKTionale

Functional constructs for Kotlin
915 stars 71 forks source link

Option.empty like Scala #27

Closed toyamah closed 6 years ago

toyamah commented 7 years ago

Hi there. Is there a method which returns Option.None like Scala. I tried to find the method but I couldn't.

MarioAriasC commented 7 years ago

No, there isn't. What is your use case? You could access None directly.

toyamah commented 7 years ago

Thank you for reply.

My use case is, when I use funKTionale with RxJava, I'd like to know a network error if accessing web API is failed.

    val networkError: Observable<Option<Throwable>> = Observable.fromIterable(1..4)
        .flatMap { page -> webApi.postData(page) }
        .map { Option.empty<Throwable>() }
        // .map { None  } if it is used, returned type is changed to None instead of Option<Throwable>
        .onErrorReturn { networkError -> networkError.toOption() }

If I use None directly, the type is changed to None instead Option<Throwable>. That' why I should cast the type.

But if I can use Option.empty<Throwable>, then the type is changed to Option<Throwable>.

MarioAriasC commented 7 years ago

Ok, I think we could include that in a future release. Not sure about naming.

Additionally, you could rise a PR, if you want.

MarioAriasC commented 6 years ago

Fix on 1.2