Maven Central Latest snapshot Kotlin version License StackOverflow Twitter

Arrow Fx. Typed FP for the masses

Arrow Fx is a next-generation Typed FP Effects Library that makes tracked effectful programming first class in Kotlin built on top of Kotlin’s suspend system and KotlinX Coroutines Arrow Fx is a functional companion to KotlinX Coroutines augmenting its api with well known functional operators making it easier to compose async and concurrent programs.

The library brings purity, referential transparency, and direct imperative syntax to typed FP in Kotlin, and is a fun and easy tool for creating Typed Pure Functional Programs.

If you’re not familiar yet with Coroutines in Kotlin, it’s recommended to first read Kotlin’s Coroutines Guide on KotlinX Coroutines.

Setup

Configure Arrow for your project

Jdk

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

Android

Arrow supports Android starting on API 21 and up.

Basic Setup

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

allprojects {
    repositories {
        mavenCentral()
    }
}

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

dependencies {
    implementation("io.arrow-kt:arrow-fx-coroutines:1.0.0")
    implementation("io.arrow-kt:arrow-fx-stm:1.0.0")
}

BOM file

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

dependencies {
    implementation(platform("io.arrow-kt:arrow-stack:1.0.0"))

    implementation("io.arrow-kt:arrow-fx-coroutines")
    implementation("io.arrow-kt:arrow-fx-stm")
}

Next development version

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

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

    // To use latest artifacts
    configurations.all { resolutionStrategy.cacheChangingModulesFor(0, "seconds") }
}

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:

def arrow_version = "1.0.0"
dependencies {
    implementation "io.arrow-kt:arrow-fx-coroutines:$arrow_version"
    implementation "io.arrow-kt:arrow-fx-stm:$arrow_version"
}

BOM file

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

def arrow_version = "1.0.0"
dependencies {
    implementation platform("io.arrow-kt:arrow-stack:$arrow_version")

    implementation "io.arrow-kt:arrow-fx-coroutines"
    implementation "io.arrow-kt:arrow-fx-stm"
}

Next development version

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

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

    // To use latest artifacts
    configurations.all { resolutionStrategy.cacheChangingModulesFor 0, 'seconds' }
}

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.5.20</kotlin.version>
    <arrow.version>1.0.0</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 1.0.0 with 1.0.1-SNAPSHOT and add this configuration:

<repository>
  <snapshotss>
    <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
    <updatePolicy>always</updatePolicy>
  </snapshots>
</repository>

Integrating with 3rd-party libraries

Arrow Fx integrates with KotlinX Coroutines Fx, Reactor framework, and any library that can model effectful async/concurrent computations as suspend.

If you are interested in the Arrow Fx library, please contact us in the #Arrow channel on the official Kotlin Lang Slack with any questions and we’ll help you along the way.

Do you like Arrow?

Arrow Org
<