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.00
# Arrow Core for iOS x64
1
2
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.
3
4
## Package Information
5
6
- **Package Name**: arrow-core-iosx64
7
- **Package Type**: maven (Kotlin Multiplatform)
8
- **Language**: Kotlin
9
- **Installation**:
10
```gradle
11
implementation("io.arrow-kt:arrow-core-iosx64:2.1.2")
12
```
13
- **Platform**: iOS x64 (Kotlin Multiplatform)
14
15
## Core Imports
16
17
```kotlin
18
import arrow.core.*
19
import arrow.core.raise.*
20
```
21
22
For specific components:
23
24
```kotlin
25
import arrow.core.Option
26
import arrow.core.Either
27
import arrow.core.Ior
28
import arrow.core.NonEmptyList
29
import arrow.core.raise.Raise
30
import arrow.core.raise.either
31
import arrow.core.raise.option
32
```
33
34
## Basic Usage
35
36
```kotlin
37
import arrow.core.*
38
import arrow.core.raise.*
39
40
// Option for nullable safety
41
val maybeUser: Option<String> = "Alice".some()
42
val result = maybeUser.map { "Hello, $it!" }.getOrElse { "No user found" }
43
44
// Either for error handling
45
val computation: Either<String, Int> = either {
46
val x = 10
47
val y = 5
48
ensure(y != 0) { "Division by zero" }
49
x / y
50
}
51
52
// NonEmptyList for guaranteed collections
53
val users = nonEmptyListOf("Alice", "Bob", "Charlie")
54
println(users.head) // Safe access to first element
55
56
// Raise DSL for typed error handling
57
fun Raise<String>.divide(x: Int, y: Int): Int {
58
ensure(y != 0) { "Cannot divide by zero" }
59
return x / y
60
}
61
62
val safeResult = recover({ divide(10, 0) }) { error ->
63
println("Error: $error")
64
0
65
}
66
```
67
68
## Architecture
69
70
Arrow Core is built around several key components:
71
72
- **Optional Types**: `Option<A>` provides functional null safety
73
- **Error Handling**: `Either<A, B>` for typed error handling and `Ior<A, B>` for partial results
74
- **Safe Collections**: `NonEmptyList<A>` and `NonEmptySet<A>` guarantee non-empty collections
75
- **Raise DSL**: Modern typed error handling with short-circuiting and error accumulation
76
- **Tuple Types**: Product types `Tuple4` through `Tuple9` for grouping multiple values
77
- **Functional Utilities**: Identity function, string escaping, and optimized generic handling
78
- **Interoperability**: Seamless conversion between types and integration with standard Kotlin types
79
80
## Capabilities
81
82
### Optional Values
83
84
Type-safe handling of nullable values with functional operations. Eliminates null pointer exceptions through the Option type.
85
86
```kotlin { .api }
87
sealed class Option<out A>
88
data class Some<out T>(val value: T) : Option<T>()
89
object None : Option<Nothing>
90
91
// Core operations
92
fun <A> Option<A>.map(f: (A) -> B): Option<B>
93
fun <A> Option<A>.flatMap(f: (A) -> Option<B>): Option<B>
94
fun <A> Option<A>.getOrElse(default: () -> A): A
95
```
96
97
[Optional Values](./optional-values.md)
98
99
### Error Handling
100
101
Typed error handling with Either and comprehensive error accumulation capabilities. Replace exceptions with explicit error types.
102
103
```kotlin { .api }
104
sealed class Either<out A, out B>
105
data class Left<out A>(val value: A) : Either<A, Nothing>()
106
data class Right<out B>(val value: B) : Either<Nothing, B>()
107
108
// Core operations
109
fun <A, B, C> Either<A, B>.map(f: (B) -> C): Either<A, C>
110
fun <A, B, C> Either<A, B>.flatMap(f: (B) -> Either<A, C>): Either<A, C>
111
fun <A, B> Either<A, B>.getOrElse(default: (A) -> B): B
112
```
113
114
[Error Handling](./error-handling.md)
115
116
### Partial Results
117
118
Handle computations that can have both success values and accumulated errors simultaneously with Ior (Inclusive OR).
119
120
```kotlin { .api }
121
sealed class Ior<out A, out B>
122
data class Left<out A>(val value: A) : Ior<A, Nothing>()
123
data class Right<out B>(val value: B) : Ior<Nothing, B>()
124
data class Both<out A, out B>(val leftValue: A, val rightValue: B) : Ior<A, B>()
125
126
// Core operations
127
fun <A, B, D> Ior<A, B>.map(f: (B) -> D): Ior<A, D>
128
fun <A, B, D> Ior<A, B>.flatMap(combine: (A, A) -> A, f: (B) -> Ior<A, D>): Ior<A, D>
129
```
130
131
[Partial Results](./partial-results.md)
132
133
### Safe Collections
134
135
Collections guaranteed to have at least one element, providing safe head/tail operations and eliminating empty collection errors.
136
137
```kotlin { .api }
138
value class NonEmptyList<out E>(val all: List<E>) : List<E>
139
140
// Properties and core operations
141
val head: E
142
val tail: List<E>
143
fun <T> map(transform: (E) -> T): NonEmptyList<T>
144
fun <T> flatMap(transform: (E) -> NonEmptyCollection<T>): NonEmptyList<T>
145
```
146
147
[Safe Collections](./safe-collections.md)
148
149
### Raise DSL
150
151
Modern typed error handling DSL with short-circuiting, error recovery, and accumulation patterns.
152
153
```kotlin { .api }
154
interface Raise<in Error> {
155
fun raise(r: Error): Nothing
156
fun <A> Either<Error, A>.bind(): A
157
fun <A> Option<A>.bind(): A // raises None for Option.None
158
}
159
160
// DSL builders
161
fun <E, A> either(block: Raise<E>.() -> A): Either<E, A>
162
fun <A> option(block: Raise<None>.() -> A): Option<A>
163
fun <E, A> recover(block: Raise<E>.() -> A, recover: (E) -> A): A
164
```
165
166
[Raise DSL](./raise-dsl.md)
167
168
### Product Types
169
170
Tuple types for grouping 4-9 values with type safety and lexicographic comparison support.
171
172
```kotlin { .api }
173
data class Tuple4<out A, out B, out C, out D>(
174
val first: A,
175
val second: B,
176
val third: C,
177
val fourth: D
178
)
179
180
// Similar structure for Tuple5 through Tuple9
181
// All provide compareTo when components are Comparable
182
```
183
184
[Product Types](./product-types.md)
185
186
## Type Definitions
187
188
### Core Type Aliases
189
190
```kotlin { .api }
191
typealias Nel<A> = NonEmptyList<A>
192
typealias EitherNel<E, A> = Either<NonEmptyList<E>, A>
193
typealias IorNel<A, B> = Ior<Nel<A>, B>
194
```
195
196
### Utility Functions
197
198
```kotlin { .api }
199
// Core utility functions
200
fun <A> identity(a: A): A
201
202
// String extensions
203
fun String.escaped(): String // Escape special characters (\n, \r, \", etc.)
204
```
205
206
### Utility Types
207
208
```kotlin { .api }
209
// For internal optimization
210
object EmptyValue {
211
fun <A> unbox(value: Any?): A
212
fun <T> combine(first: Any?, second: T, combine: (T, T) -> T): T
213
fun <T, R> fold(value: Any?, ifEmpty: () -> R, ifNotEmpty: (T) -> R): R
214
}
215
```
216
217
### Collection Extensions
218
219
Extensive functional programming extensions for Iterable, Sequence, and Map collections, including multi-argument zip, error accumulation, padding, and alignment operations.
220
221
```kotlin { .api }
222
// Multi-argument zip operations
223
fun <A, B, C, D> Iterable<A>.zip(
224
b: Iterable<B>,
225
c: Iterable<C>,
226
transform: (A, B, C) -> D
227
): List<D>
228
229
// Error accumulation patterns
230
fun <Error, A, B> Iterable<A>.mapOrAccumulate(
231
transform: RaiseAccumulate<Error>.(A) -> B
232
): Either<NonEmptyList<Error>, List<B>>
233
234
// Padding and alignment
235
fun <A, B> Iterable<A>.padZip(other: Iterable<B>): List<Pair<A?, B?>>
236
fun <A, B> Iterable<A>.align(b: Iterable<B>): List<Ior<A, B>>
237
```
238
239
[Collection Extensions](./collection-extensions.md)
240
241
### Utility Functions
242
243
Core utility functions, type aliases, and extensions that enhance Kotlin's standard library with functional programming patterns.
244
245
```kotlin { .api }
246
// Core utilities
247
fun <A> identity(a: A): A
248
fun <P1, T> constant(t: T): (P1) -> T
249
250
// String extensions
251
fun String.escaped(): String
252
253
// Type aliases
254
typealias Predicate<T> = (T) -> Boolean
255
typealias Nel<A> = NonEmptyList<A>
256
typealias EitherNel<E, A> = Either<NonEmptyList<E>, A>
257
```
258
259
[Utility Functions](./utility-functions.md)
260