Functional companion to Kotlin's Standard Library providing type-safe error handling and functional programming constructs for iOS x64 target
npx @tessl/cli install tessl/maven-io-arrow-kt--arrow-core-iosx64@2.1.0Arrow Core is a comprehensive functional programming library for Kotlin that serves as a functional companion to Kotlin's Standard Library. It provides essential data types like Option and Either for type-safe error handling, functional operators like zipOrAccumulate, and computation blocks for writing pure functional programming applications. This iOS x64 variant is compiled for iOS platforms as part of Kotlin Multiplatform support.
implementation("io.arrow-kt:arrow-core-iosx64:2.1.2")import arrow.core.*
import arrow.core.raise.*For specific components:
import arrow.core.Option
import arrow.core.Either
import arrow.core.Ior
import arrow.core.NonEmptyList
import arrow.core.raise.Raise
import arrow.core.raise.either
import arrow.core.raise.optionimport arrow.core.*
import arrow.core.raise.*
// Option for nullable safety
val maybeUser: Option<String> = "Alice".some()
val result = maybeUser.map { "Hello, $it!" }.getOrElse { "No user found" }
// Either for error handling
val computation: Either<String, Int> = either {
val x = 10
val y = 5
ensure(y != 0) { "Division by zero" }
x / y
}
// NonEmptyList for guaranteed collections
val users = nonEmptyListOf("Alice", "Bob", "Charlie")
println(users.head) // Safe access to first element
// Raise DSL for typed error handling
fun Raise<String>.divide(x: Int, y: Int): Int {
ensure(y != 0) { "Cannot divide by zero" }
return x / y
}
val safeResult = recover({ divide(10, 0) }) { error ->
println("Error: $error")
0
}Arrow Core is built around several key components:
Option<A> provides functional null safetyEither<A, B> for typed error handling and Ior<A, B> for partial resultsNonEmptyList<A> and NonEmptySet<A> guarantee non-empty collectionsTuple4 through Tuple9 for grouping multiple valuesType-safe handling of nullable values with functional operations. Eliminates null pointer exceptions through the Option type.
sealed class Option<out A>
data class Some<out T>(val value: T) : Option<T>()
object None : Option<Nothing>
// Core operations
fun <A> Option<A>.map(f: (A) -> B): Option<B>
fun <A> Option<A>.flatMap(f: (A) -> Option<B>): Option<B>
fun <A> Option<A>.getOrElse(default: () -> A): ATyped error handling with Either and comprehensive error accumulation capabilities. Replace exceptions with explicit error types.
sealed class Either<out A, out B>
data class Left<out A>(val value: A) : Either<A, Nothing>()
data class Right<out B>(val value: B) : Either<Nothing, B>()
// Core operations
fun <A, B, C> Either<A, B>.map(f: (B) -> C): Either<A, C>
fun <A, B, C> Either<A, B>.flatMap(f: (B) -> Either<A, C>): Either<A, C>
fun <A, B> Either<A, B>.getOrElse(default: (A) -> B): BHandle computations that can have both success values and accumulated errors simultaneously with Ior (Inclusive OR).
sealed class Ior<out A, out B>
data class Left<out A>(val value: A) : Ior<A, Nothing>()
data class Right<out B>(val value: B) : Ior<Nothing, B>()
data class Both<out A, out B>(val leftValue: A, val rightValue: B) : Ior<A, B>()
// Core operations
fun <A, B, D> Ior<A, B>.map(f: (B) -> D): Ior<A, D>
fun <A, B, D> Ior<A, B>.flatMap(combine: (A, A) -> A, f: (B) -> Ior<A, D>): Ior<A, D>Collections guaranteed to have at least one element, providing safe head/tail operations and eliminating empty collection errors.
value class NonEmptyList<out E>(val all: List<E>) : List<E>
// Properties and core operations
val head: E
val tail: List<E>
fun <T> map(transform: (E) -> T): NonEmptyList<T>
fun <T> flatMap(transform: (E) -> NonEmptyCollection<T>): NonEmptyList<T>Modern typed error handling DSL with short-circuiting, error recovery, and accumulation patterns.
interface Raise<in Error> {
fun raise(r: Error): Nothing
fun <A> Either<Error, A>.bind(): A
fun <A> Option<A>.bind(): A // raises None for Option.None
}
// DSL builders
fun <E, A> either(block: Raise<E>.() -> A): Either<E, A>
fun <A> option(block: Raise<None>.() -> A): Option<A>
fun <E, A> recover(block: Raise<E>.() -> A, recover: (E) -> A): ATuple types for grouping 4-9 values with type safety and lexicographic comparison support.
data class Tuple4<out A, out B, out C, out D>(
val first: A,
val second: B,
val third: C,
val fourth: D
)
// Similar structure for Tuple5 through Tuple9
// All provide compareTo when components are Comparabletypealias Nel<A> = NonEmptyList<A>
typealias EitherNel<E, A> = Either<NonEmptyList<E>, A>
typealias IorNel<A, B> = Ior<Nel<A>, B>// Core utility functions
fun <A> identity(a: A): A
// String extensions
fun String.escaped(): String // Escape special characters (\n, \r, \", etc.)// For internal optimization
object EmptyValue {
fun <A> unbox(value: Any?): A
fun <T> combine(first: Any?, second: T, combine: (T, T) -> T): T
fun <T, R> fold(value: Any?, ifEmpty: () -> R, ifNotEmpty: (T) -> R): R
}Extensive functional programming extensions for Iterable, Sequence, and Map collections, including multi-argument zip, error accumulation, padding, and alignment operations.
// Multi-argument zip operations
fun <A, B, C, D> Iterable<A>.zip(
b: Iterable<B>,
c: Iterable<C>,
transform: (A, B, C) -> D
): List<D>
// Error accumulation patterns
fun <Error, A, B> Iterable<A>.mapOrAccumulate(
transform: RaiseAccumulate<Error>.(A) -> B
): Either<NonEmptyList<Error>, List<B>>
// Padding and alignment
fun <A, B> Iterable<A>.padZip(other: Iterable<B>): List<Pair<A?, B?>>
fun <A, B> Iterable<A>.align(b: Iterable<B>): List<Ior<A, B>>Core utility functions, type aliases, and extensions that enhance Kotlin's standard library with functional programming patterns.
// Core utilities
fun <A> identity(a: A): A
fun <P1, T> constant(t: T): (P1) -> T
// String extensions
fun String.escaped(): String
// Type aliases
typealias Predicate<T> = (T) -> Boolean
typealias Nel<A> = NonEmptyList<A>
typealias EitherNel<E, A> = Either<NonEmptyList<E>, A>