Arrow v0.10.3 is now available
by Simon Vergauwen
- •
- November 15, 2019
- •
- kotlin• functional• arrow
- |
- 5 minutes to read.

The latest Arrow release includes some new and exciting features that bring us another step closer to 1.0 with Arrow Meta on the horizon. If you’re new to Arrow, it’s an open-source library that’s packed with data types and type classes that empower pure functional programming in Kotlin.
Deprecation of Try
Arrow’s goal is to offer a public API consisting of only pure functions. Therefore, we mark side-effects with suspend
or we wrap them into an effectful type such as IO
.
Try
can never yield pure functions since it’s eager and executes the effects on construction;
it can only be made pure by marking it as suspend
. Since Try<A>
is isomorphic to Either<Throwable, A>
, we can deprecate Try
and replace its constructor for a smart constructor for Either
.
data class User(val name: String)
suspend fun <A> Either.Companion.catch(f: suspend () -> A): Either<Throwable, A> =
try { f().right() } catch (t: Throwable) { t.left() }
suspend fun getUser(): Either<Throwable, User> Either.catch {
User("FP'er")
}
What’s new in Arrow Fx
Simplifying Fx
The Fx
typeclass has been removed from Arrow and its functionality is now merged into the typeclass hierarchy.
If you were using Fx
for concrete data types like IO
, Option
, Either
, etc. you can now do so by calling the fx
function on their companion object
s.
import arrow.core.fx
val option = Option.fx {
val one = !Some(1)
val two = !Some(2)
one + two
}
To use fx
within the typeclass hierarchy ,you can call the property fx
and then the named DSL for the syntax you want enabled:
import arrow.fx.Concurrent
fun io(CF: Concurrent<ForIO>): IO<Int> = CF.run {
fx.concurrent {
val one = !IO(1)
val two = !IO(2)
one + two
}
}
The following DSLs are available:
Typeclass | New API | Old API |
---|---|---|
Monad | fx.monad | binding |
MonadThrow | fx.monadThrow | bindingCatch |
MonadFilter | fx.monadFilter | bindingFilter |
Async | fx.async | / |
Comonad/Bimonad | fx.comonad | / |
MonadDefer | / | bindingCancelable |
Concurrent | fx.concurrent | bindingConcurrent |
Note that bindingCancelable
was removed because it belongs to the typeclass ConcurrentEffect
, which is still a work in progress.
With the upcoming release of Arrow Meta, this could be further cleaned up!
Suspended
Effect types can now interoperate with suspend
and you can go back and forth between IO
, Single
, Mono
, etc. and suspend
using suspended()
and effect
.
effect
already exists in the typeclass hierarchy, and a typeclass for suspended
will soon be included in Arrow Fx.
suspend fun main(): Unit {
val request: Either<Throwable, User> =
IO.effect(Dispatchers.IO) { getUser() }
.attempt()
.suspended()
val text = request.fold({ "No user" }, { it.name })
IO.effect(Dispatchers.Main) { displayUi(text) }.suspended()
}
New concurrency tools
Arrow v.0.10.3 includes a bunch of powerful new concurrency operators such as parTraverse
, parSequence
, and sleep
.
val io = IO.fx {
!listOf(1, 2, 3).parTraverse { i ->
IO.effect { println("$i ==> ${Thread.currentThread().name} ") }
}
!IO.effect { println("Going to take a nap now!") }
!IO.sleep(2.seconds)
!IO.effect { println("Woke up after an extreme powernap!") }
}
For a full list of changes and features in 0.10.3 please visit the official changelog.
We would like to give special thanks to the following contributors for this version (in no particular order):
- Stanislav Zemlyakov
- Rachel M. Carmena
- Sven Tennie
- Flavio Corpa
- Simon Vergauwen
- Paco Estevez
- Tatsuya Fujisaki
- Alphonse Bendt
- Sebastian Raaphorst
- Jannis
- Ro-Rams
- Miguel Angel Ruiz Lopez
- junron
- Stephen Samuel
- Alberto Ballano
- Thanh Le
- Francisco Diaz
For a full list of the contributors who have helped Arrow get to where it is today, please check out: Arrow Contributors. We’re always looking for additional help, please view the guidelines for contributing and take a look at the help-wanted issues. All levels are welcome and we offer 1:1 mentoring through Arrow’s Slack and Gitter channels.
If you would like to support Arrow, but don’t have the time to invest in contributing, consider picking up some Arrow swag! All proceeds are invested back into advancing the library.
Resources:
- Arrow on Twitter
- Arrow on Gitter
- #Arrow on Kotlin Slack
- Arrow Presentations Playlist
- Functional Programming in Kotlin with Arrow web series
The active development of Arrow is proudly sponsored by 47 Degrees, a Functional Programming consultancy with a focus on the Scala, Kotlin, Haskell, and Swift programming languages.