Arrow 1.0 is now available
by Raúl Raja Martínez
- •
- September 20, 2021
- •
- arrow• kotlin• functional programming
- |
- 5 minutes to read.
We are pleased to announce the general release of Arrow 1.0!
Arrow is a collection of libraries that complement the Kotlin ecosystem with functional patterns and data types.
The Arrow 1.0 release marks the first commitment to stability after a long journey over five years of work. The amazing efforts and enthusiasm of more than 200 individual contributors and companies like 47 Degrees and Instil make this project possible.
The 1.0 release is an extended maintenance release where we will preserve binary compatibility through the series to serve as a foundation for applications and other libraries. In parallel, we will be working on new features, including new backend-oriented libraries and compiler plugins that will get independently released throughout the year.
Among the most noteworthy features in 1.0, we want to highlight:
Multiplatform Support
In Arrow 1.0, Arrow now gets tested and distributed on the different multiplatform targets supported by Kotlin, including JVM, Native, and JS. That means that you can use Arrow in all your Kotlin projects.
Arrow Core : Computation Expressions
Built atop the Kotlin suspension system, Arrow enables the development of computation expressions for data types like Result
, Either
, and Validated
. Using the either
block, for example, gives users concise imperative syntax over Either
, and eliminates the need for flatMap
or callback style programming. This actually works over many other monadic data types.
suspend fun prepareLunch(): Either<CookingException, Salad> =
either<CookingException, Salad> {
val lettuce = takeFoodFromRefrigerator().bind()
val knife = getKnife().bind()
val lunch = prepare(knife, lettuce).bind()
lunch
}
Arrow Fx : Parallel zip, traverse, and sequence
Arrow Fx, a functional companion to KotlinX Coroutines, provides operators that make concurrent and async programming with suspending functions a more enjoyable ride. In the same spirit as computation expressions, Arrow Fx comes with built-in versions of parZip, parTraverse, parSequence, and other high-level composable operators.
//maps each function to `::employee` in parallel
val audrey = parZip(
{ "Audrey" },
{ company("Arrow") }
) { name, company -> Employee(name, company) }
val pepe = parZip(
{ "Pepe" },
{ company("Arrow") }
) { name, company -> Employee(name, company) }
val candidates = listOf(audrey, pepe)
val employees = candidates.parTraverse { hire(it) } //hires in parallel
Arrow Optics : Deep access to immutable data
Arrow Optics understands the shape of sealed, data classes, collections, and Arrow Core data types. Lenses, and optics more broadly, are very useful abstractions to access such immutable data.
val audrey =
Employee("Audrey Tang",
Company("Arrow",
Address("Functional city",
Street(47, "lambda street"))))
val modified = Employee.company.address.street.name
.modify(audrey, String::uppercase)
Arrow Meta : Kotlin metaprogramming
The Arrow team and 47 Degrees are using Arrow Meta to develop compiler plugins in the space of formal verification. As part of these ongoing efforts, we expect to release Arrow Analysis after the release of Arrow 1.0.
Arrow Analysis is a Kotlin compiler plugin focused on making applications safer by declaring pre, post, and invariant conditions over functions that get validated at compile time.
@Law
fun Int.safeDiv(other: Int): Int {
pre(other != 0) { "other is not zero" }
return this / other //decorates Int.div with preconditions
}
fun foo() {
val result = 1 / 0
// compile time error:
// call to 1 / 0 fails to satify `safeDiv` law precondition
}
Release 0.13.3
In addition to 1.0, we are relasing 0.13.3 alongside it, providing a deprecation cycle for the following APIs that won’t be available in 1.0.
foldRight
and all lazy folds are being deprecated, as a normal fold can sufficiently cover all its use cases as long as it’s inline. See https://github.com/arrow-kt/arrow/pull/2370 for more information.tailRecM
is removed in favor of tailrec and DeepRecursiveFunction.tailRecM
is deprecated together with theKind
type classes since it’s meant for writing kind-based polymorphic stack-safe programs.Monoid/Semigroup
forFloat/Double
are deprecated due to unlawful equality on floating-point numbers.
Join us on this journey
These are just a few of the highlights you can find in Arrow’s 1.0 release. For more detailed info and documentation, please visit Arrow-kt.io
We are deeply grateful to all of Arrow’s contributors for following this journey and pushing over the years to make Arrow a success and this 1.0 release a reality.
If you are interested in contributing, learning, or have any questions about Arrow and the release, don’t be shy and join us on the Kotlin Slack in the #arrow channel. We are an inclusive group of people committed to providing the best experience to our users and community, and we look forward to seeing you there!