Functional Domain Modeling with Arrow's Core Types
Model complex domains using Either, NonEmptyList, and validated error accumulation.
What Is Functional Domain Modeling?
Functional domain modeling uses algebraic types (Either, Option, sealed classes) to encode business rules into types. Invalid states become unrepresentable at compile time, and errors are explicit in function signatures — no hidden exceptions.
Value Objects with Inline/Value Classes
Use Kotlin value classes to wrap primitives and prevent primitive obsession. The type system rejects passing a UserId where a PostId is expected:
@JvmInline value class UserId(val value: Long)
@JvmInline value class PostId(val value: Long)
fun findUser(id: UserId): Either<UserError, User> = TODO()
// findUser(PostId(1L)) // Compile error!All lessons in this course
- Either : Typed Error Handling Without Exceptions
- Arrow Raise DSL: Composing Typed Errors
- Option and Nullable: When to Use Each
- Functional Domain Modeling with Arrow's Core Types