arrow-refined-types / arrow.refinement.collections / Empty

Empty

class Empty

Empty constrains a collection to be empty

Safe nullable construction

import arrow.refinement.collections.Empty

Empty.orNull(listOf(1, 2))
Empty.orNull(emptyList<Int>())
// []

Resolved constraints

Empty.constraints(listOf(1, 2))
// [(false, Expected empty iterable but found [1, 2])]
Empty.constraints(emptyList<Int>())
// [(true, Expected empty iterable but found [])]
Empty.isValid(listOf(1, 2))
// false
Empty.isValid(emptyList<Int>())
// true

Folding validation

Empty.fold(listOf(1, 2), { "failed: $it" }, { "success: $it" })
// failed: [(false, Expected empty iterable but found [1, 2])]
Empty.fold(emptyList<Int>(), { "failed: $it" }, { "success: $it" })
// success: Empty(value=[])

Unsafe require

Empty.require(emptyList<Int>())
// []
try { Empty.require(listOf(2, 3)) } catch (e: IllegalArgumentException) { e.message }
// Expected empty iterable but found [2, 3]

Types

Companion companion object Companion : Refined<Iterable<*>, Empty>

Properties

value val value: Iterable<*>

Do you like Arrow?

Arrow Org
<