Maven Central Latest snapshot Kotlin version License StackOverflow Twitter

Λrrow is a library for Typed Functional Programming in Kotlin.

Arrow complements the Kotlin standard library and KotlinX Coroutines libraries with functional patterns that favor composition, effect control, and immutability.

Arrow is composed of 4 main modular libraries:

  • Core: Arrow Core includes types such as Either, Validated and many extensions to Iterable that can be used when implementing error handling patterns. Core also includes the base continuation effects system, which includes patterns to remove callbacks and enables controlled effects in direct syntax. Some applications of the effect system reduce boilerplate and enable direct syntax including monad comprehensions and computation expressions.

  • Fx: Arrow Fx is a full-featured, high-performance, asynchronous framework that brings functional operators to Kotlin’s suspend functions. By leveraging the power of KotlinX Coroutines and the compiler support for CPS transformations, Arrow Fx results in optimal async programs with increased throughput and decreased allocations.

  • Optics: Arrow Optics provides an automatic DSL that allows users to use . notation when accessing, composing, and transforming deeply nested immutable data structures. Optics also offers all the base types such as Lens, Prism, and others from which we can generalize accessing and traversing deep values in sealed and data classes models.

  • Meta: Arrow Meta is a general purpose library for meta-programming in Kotlin to build compiler plugins. Some type system features proposed by Arrow such as union types, product types, proof derivation, and others are built with Arrow Meta and serve as examples of what could be incorporated in the Kotlin compiler.

Setup

JDK

Make sure to have the latest version of JDK 1.8 installed.

Android

Arrow supports Android starting on API 21 and up.

Gradle

Basic Setup

In your project’s root build.gradle, append this repository to your list:

allprojects {
    repositories {
        mavenCentral()
    }
}

Add the dependencies into the project’s build.gradle:

Arrow Core
def arrow_version = "0.13.1"
dependencies {
    implementation "io.arrow-kt:arrow-core:$arrow_version"
}
Arrow Core + Arrow Optics
apply plugin: 'kotlin-kapt'

def arrow_version = "0.13.1"
dependencies {
    implementation "io.arrow-kt:arrow-optics:$arrow_version"
    kapt    "io.arrow-kt:arrow-meta:$arrow_version"
}
Arrow Core + Arrow Fx
def arrow_version = "0.13.1"
dependencies {
    implementation "io.arrow-kt:arrow-fx-coroutines:$arrow_version"
}

BOM file

To avoid specifying the Arrow version for every dependency, a BOM file is available:

    implementation platform("io.arrow-kt:arrow-stack:$arrow_version")

    implementation "io.arrow-kt:arrow-core"
    implementation "io.arrow-kt:arrow-fx-coroutines"
    ...

Maven

Basic Setup

Make sure to have at least the latest version of JDK 1.8 installed. Add to your pom.xml file the following properties:

<properties>
    <kotlin.version>1.4.0</kotlin.version>
    <arrow.version>0.13.1</arrow.version>
</properties>

Add the dependencies that you want to use:

        <dependency>
            <groupId>io.arrow-kt</groupId>
            <artifactId>arrow-core</artifactId>
            <version>${arrow.version}</version>
        </dependency>

Enabling kapt for the Optics DSL

For the Optics DSL, enable annotation processing using Kotlin plugin:

<plugin>
    <groupId>org.jetbrains.kotlin</groupId>
    <artifactId>kotlin-maven-plugin</artifactId>
    <version>${kotlin.version}</version>
    <executions>
        <execution>
            <id>kapt</id>
            <goals>
                <goal>kapt</goal>
            </goals>
            <configuration>
                <sourceDirs>
                    <sourceDir>src/main/kotlin</sourceDir>
                </sourceDirs>
                <annotationProcessorPaths>
                    <annotationProcessorPath>
                        <groupId>io.arrow-kt</groupId>
                        <artifactId>arrow-meta</artifactId>
                        <version>${arrow.version}</version>
                    </annotationProcessorPath>
                </annotationProcessorPaths>
            </configuration>
        </execution>
        <execution>
            <id>compile</id>
            <phase>compile</phase>
            <goals>
                <goal>compile</goal>
            </goals>
            <configuration>
                <sourceDirs>
                    <sourceDir>src/main/kotlin</sourceDir>
                </sourceDirs>
            </configuration>
        </execution>
        <execution>
            <id>test-compile</id>
            <phase>test-compile</phase>
            <goals>
                <goal>test-compile</goal>
            </goals>
        </execution>
    </executions>
</plugin>

BOM file

To avoid specifying the Arrow version for every dependency, a BOM file is available:

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>io.arrow-kt</groupId>
        <artifactId>arrow-stack</artifactId>
        <version>${arrow.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    ...
  </dependencies>

Next development version

If you want to try the latest features, replace 0.13.1 with 1.0.0-SNAPSHOT and add this repository:

allprojects {
    repositories {
        ...
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
    }
}

Do you like Arrow?

Arrow Org
<