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

Tail

class Tail<A>

Tail constrains a collection ensuring its tail matches Elements

Safe nullable construction

import arrow.refinement.collections.Tail

Tail.Elements(listOf(2, 3)).orNull(listOf(1, 2, 3))
// [1, 2, 3]
Tail.Elements(listOf(3, 4)).orNull(listOf(1, 2, 3))

Resolved constraints

Tail.Elements(listOf(2, 3)).constraints(listOf(1, 2, 3))
// [(true, Expected tail: [[2, 3]] to be [2, 3])]
Tail.Elements(listOf(3, 4)).constraints(listOf(1, 2, 3))
// [(false, Expected tail: [[2, 3]] to be [3, 4])]
Tail.Elements(listOf(2, 3)).isValid(listOf(1, 2, 3))
// true
Tail.Elements(listOf(3, 4)).isValid(listOf(1, 2, 3))
// false

Folding validation

Tail.Elements(listOf(2, 3)).fold(listOf(1, 2, 3), { "failed: $it" }, { "success: $it" })
// success: Tail(value=[1, 2, 3])
Tail.Elements(listOf(3, 4)).fold(listOf(1, 2, 3), { "failed: $it" }, { "success: $it" })
// failed: [(false, Expected tail: [[2, 3]] to be [3, 4])]

Unsafe require

Tail.Elements(listOf(2, 3)).require(listOf(1, 2, 3))
// [1, 2, 3]
try { Tail.Elements(listOf(3, 4)).require(listOf(1, 2, 3)) } catch (e: IllegalArgumentException) { e.message }
// Expected tail: [[2, 3]] to be [3, 4]

Types

Elements class Elements<A> : Refined<Iterable<A>, Tail<A>>

Properties

value val value: Iterable<A>

Do you like Arrow?

Arrow Org
<