or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

collection-extensions.mderror-handling.mdindex.mdoptional-values.mdpartial-results.mdproduct-types.mdraise-dsl.mdsafe-collections.mdutility-functions.md
tile.json

tessl/maven-io-arrow-kt--arrow-core-iosx64

Functional companion to Kotlin's Standard Library providing type-safe error handling and functional programming constructs for iOS x64 target

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/io.arrow-kt/arrow-core-iosx64@2.1.x

To install, run

npx @tessl/cli install tessl/maven-io-arrow-kt--arrow-core-iosx64@2.1.0

index.mddocs/

Arrow Core for iOS x64

Arrow 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.

Package Information

  • Package Name: arrow-core-iosx64
  • Package Type: maven (Kotlin Multiplatform)
  • Language: Kotlin
  • Installation:
    implementation("io.arrow-kt:arrow-core-iosx64:2.1.2")
  • Platform: iOS x64 (Kotlin Multiplatform)

Core Imports

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.option

Basic Usage

import 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
}

Architecture

Arrow Core is built around several key components:

  • Optional Types: Option<A> provides functional null safety
  • Error Handling: Either<A, B> for typed error handling and Ior<A, B> for partial results
  • Safe Collections: NonEmptyList<A> and NonEmptySet<A> guarantee non-empty collections
  • Raise DSL: Modern typed error handling with short-circuiting and error accumulation
  • Tuple Types: Product types Tuple4 through Tuple9 for grouping multiple values
  • Functional Utilities: Identity function, string escaping, and optimized generic handling
  • Interoperability: Seamless conversion between types and integration with standard Kotlin types

Capabilities

Optional Values

Type-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): A

Optional Values

Error Handling

Typed 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): B

Error Handling

Partial Results

Handle 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>

Partial Results

Safe Collections

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>

Safe Collections

Raise DSL

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): A

Raise DSL

Product Types

Tuple 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 Comparable

Product Types

Type Definitions

Core Type Aliases

typealias Nel<A> = NonEmptyList<A>
typealias EitherNel<E, A> = Either<NonEmptyList<E>, A>
typealias IorNel<A, B> = Ior<Nel<A>, B>

Utility Functions

// Core utility functions
fun <A> identity(a: A): A

// String extensions
fun String.escaped(): String  // Escape special characters (\n, \r, \", etc.)

Utility Types

// 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
}

Collection Extensions

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>>

Collection Extensions

Utility Functions

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>

Utility Functions