Satyam Agarwal
03/30/2022, 12:00 PMReturning type parameter has been inferred to Nothing implicitly. Please specify type arguments explicitly to hide this warning. Nothing can produce an exception at runtime.
What are the implications of this, apart from readability that MyError.left().bind()
is not clear in what the RHS can be.
iirc, its not trivial to remove these errors, they can only be suppressed. Is there any work being done in fixing this ?
Also, MyError.left().bind()
is this recommended approach ? I often use filterOrOther to avoid warnings.mitch
03/30/2022, 12:08 PMMyError.left().bind<Unit>()
Satyam Agarwal
03/30/2022, 12:10 PM.bind()
is whole another conversationsimon.vergauwen
03/30/2022, 12:19 PMIs there any work being done in fixing this ?I'm not sure what needs fixing here 😅 The warning is coming from Kotlin Std, if you want to work around it the most straightforward thing would be to create a function that infers something else than
Nothing
.
fun <A> myError(): Either<MyError, A> = MyError.left()
That way Unit
can be inferred here, and the Nothing
warning will dissapear.mitch
03/30/2022, 12:25 PMMonadError[F[_], E].raiseError(err: E): F[A]
with A being always Unit. Not sure if that is less or more inconvenient.
suspend fun <L> RestrictedEitherEffect<L, *>.reject(leftValue: L): Unit = leftValue.left().bind<Unit>()
suspend fun <L> EitherEffect<L, *>.reject(leftValue: L): Unit = leftValue.left().bind<Unit>()
sealed class MyError {
data class SomeErrorType(val value: String) : MyError()
}
fun main() {
val x = either.eager<MyError, Int> {
reject(MyError.SomeErrorType("123"))
5
}
println(x)
// Either.Left(SomeErrorType(value=123))
}
mitch
03/30/2022, 12:30 PMsimon.vergauwen
03/30/2022, 12:31 PMshift
which we'll have in the next Arrow release.
https://github.com/arrow-kt/arrow/blob/main/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/EffectScope.kt#L31
You'll also not have to wrap your error into Left
anymore first.simon.vergauwen
03/30/2022, 12:31 PMshift
soon.mitch
03/30/2022, 12:33 PMmitch
03/30/2022, 12:47 PMshift()
as an alias as well? seems we’ll write shift(None)
everywhere. right now we had reject()
for option { }
.
https://github.com/arrow-kt/arrow/blob/main/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/option.kt#L19Satyam Agarwal
03/30/2022, 12:54 PMshift
sounds cool.simon.vergauwen
03/30/2022, 1:26 PMsimon.vergauwen
03/30/2022, 1:27 PMshift()
alias in Option
sounds good.phldavies
03/30/2022, 8:19 PMensure(false) { MyError }
not do the same thing for now?simon.vergauwen
03/31/2022, 7:01 AM