Resolving deprecations when migrating 0.9.0 -> 1.2.0 #3302
-
|
I have a legacy project which is using Arrow 0.9.0 and I'm trying to migrate to 1.2.0. I managed to resolve all issues, except two. Some parts of code have something like: fun old(): Either<Throwable, Unit> =
Either.right(5)
.map { log.info(it) }
.unit()which I replaced with fun new(): Either<Throwable, Unit> =
Either.right(5)
.map { log.info(it) }
.map {}but Other situation is with fun old(): Either<Throwable, Int> =
Either.cond(
2 == 2,
ifTrue = { 2 },
ifFalse = { RuntimeException() }
)which I replaced with fun new(): Either<Throwable, Int> =
Either.conditionally(
2 == 2,
ifTrue = { 2 },
ifFalse = { RuntimeException() }
)but |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
context(_: Raise<Throwable>)
fun ex1() { log.info(5) }
context(_: Raise<Throwable>)
fun ex2(): Int = if (2 == 2) 2 else raise(RuntimeException())
// or even
context(_: Raise<Throwable>)
fun ex2(): Int {
ensure(2 == 2) { RuntimeException() }
return 2
} |
Beta Was this translation helpful? Give feedback.
map {}is probably the easiest way to signal your intent here.For conditionally, you can just use
if (2 == 2) 2.right() else RuntimeException().left()The better way is to use
Raise: