Skip to main content

Quickstart

Arrow aims to be the perfect companion to your Kotlin journey. That means it focuses on tasks most developers deal with, like modifying data or managing resources. Given these aims, Arrow strives to provide idiomatic solutions and integrate with core Kotlin concepts such as coroutines.

Arrow is inspired by the great work made in other programming language communities, especially from functional, data-oriented and concurrent programming. This doesn't mean you need to know any of those ideas to use the libraries; Arrow exposes these concepts in ways that do not feel alien to Kotlin programmers.

DSLs

Arrow uses Domain Specific Languages (DSLs) to provide a more concise syntax for many tasks. This is just a fancy way of saying that Arrow libraries often have a core function that ought to be called with a lambda, and inside that new scope you get access to additional behaviors.

Typed errors

With Arrow you can succinctly describe what kind of domain errors may arise in your functions. This brings extra clarity to your code, as you can more easily track what failure may happen, and also extra safety, as the compiler will ensure that you don't forget to handle a possible error.

Arrow does not only provide fail-first behavior for errors, but also error accumulation. This is especially useful when validating user input, as you often want to report as many problems at once.

Concurrency and resources

Kotlin coroutines are a powerful mechanism for concurrency. However, sometimes you need to describe what you want to happen in more detail than you may want. Arrow provides higher-level constructs that focus on the intent: parallelism and racing (executing several computations concurrently but waiting only for the first one). Cancellations and exceptions are handled following the Structured Concurrency principles.

Allocation and release of resources is not easy, especially when we have multiple resources that depend on each other. The Resource DSL adds the ability to install resources and ensure proper finalization even in the face of exceptions and cancellations. Furthermore, your code moves from a mess of nested trys or uses to a linear sequence of operations.

Sharing data across multiple concurrent computations is always tricky, especially when this data is not just a single atomic value. Arrow provides a higher level notion of transactions for your state, providing protection for whole execution blocks, and introducing the notion of rollback for failed computations.

Resilience

Most, if not all, of the systems we develop nowadays require the cooperation of other services, which may live in the same process, on the same machine, or may require some network communication. This creates a lot of different potential scenarios where things may fail. Arrow provides a simple yet powerful way to define policies for retrying failed computations.

In even more complex scenarios simple retry may not be the solution. This is especially true when a service is overloaded, since additional interaction may only worsen its overloaded state. Arrow provides a circuit breaker mechanism that can be shared between concurrent computations, with a much better protocol to resume execution until several failed attempts.

Immutable data

Immutable data has many advantages in terms of safety — and Kotlin makes it easy to use them with data classes and sealed hierarchies. However, updating those structures using only the provided copy may become quite tedious if the data is nested. Arrow optics give you the tools to write the concise code you always wanted.

The other difficult part of immutable data is traversing collections, either to aggregate data or to modify some part of them. Fortunately, the optics mechanism also applies to collections, so all of your immutable data manipulation can use the same vocabulary.

And more!

This was just a quick overview of the main features provided by Arrow. Smaller utilities for collections, functions, coroutines, and errors, are also part of the ecosystem. The docs describe (almost) all of them, so just take a look around and find what you may need.

Give it a try?