```fun foo(): Try<Unit> { return Try { ...
# arrow
r
Copy code
fun foo(): Try<Unit> {
    return Try {
        1 // doesn't compile
    }
}
b
Try { 1 }.map { Unit }
?
although I would expect that using
.fold(failure, success)
would be more useful in general
r
but the caller does that. I still do this
twitter futures in Scala had this thing
Future.value("foo").unit
was hoping there was a similar thing on
Try
in arrow but
map
will do\
thanks
b
Try { 1 }.unit()
works
IIRC the design philosophy behind Arrow was to mimic cats/cats-effect where it makes sense, so if you see something in cats it probably exists (or will exist) in Arrow as well
maybe just with a different syntax
r
Copy code
import arrow.core.*
import arrow.core.extensions.`try`.functor.*

Try { "Hello World" }.unit()
//Success(value=kotlin.Unit)
This won't work if your Try is in already failed state
since
unit
is right biased. If you want to return Unit inside
Try
when your
Try
is a failure you can use
handleError { Unit }
r
thanks @raulraja
👍 1
didn’t fully get the part with the failure. usually when I use Try, I don’t know if it will succeed or fail. if it fails I am not expecting it to return unit but to wrap an exception.
hmm shouldn’t the functors be in
io.arrow-kt:arrow-typeclasses
it doesn’t import arrow.core.extensions in gradle
r
Functor
is in
arrow-typeclasses
but the Functor extensions for a given data type are in the extensions module. In this case
arrow-core-extensions
which you may have to include in your build file.
r
thanks