arrow-refined-types / arrow.refinement / Refined

Refined

abstract class Refined<A, out B>

Abstract class for all Refined predicates.

The example below shows a refined type Positive that ensures Int is > than 0. By convention we make the type companion extend the Refined class to distinguish between the value type representing the types being refined and the actual predicates and their composition.

import arrow.refinement.Refined
import arrow.refinement.ensure

@JvmInline
value class Positive /* private constructor */(val value: Int) {
 companion object : Refined<Int, Positive>(::Positive, {
   ensure((it > 0) to "$it should be > 0")
 })
}

Constructors

<init> Constructor that automatically composes with and all predicates as constrains to call fRefined(f: (A) -> B, vararg predicates: Refined<A, *>)
Abstract class for all Refined predicates.Refined(f: (A) -> B, constraints: (A) -> Constraints)

Properties

constraints Validation function that validates Constraints for a given value of Aval constraints: (A) -> Constraints
f Refined type constructor that will be applied if constraints invocation results in a list of valid Constraintsval f: (A) -> B

Functions

and Composition of all the Constraints of this predicate with the constraints of otherinfix fun <C> and(other: Refined<A, C>): Refined<A, C>
fold Validates value invoking ifInvalid in the case of failure and ifValid in the case of success.fun <C> fold(value: A, ifInvalid: (Constraints) -> C, ifValid: (B) -> C): C
invoke When using the compiler plugin calls to this function get validated at compile time when using constants or suggested to use the orNull variant for safe access.operator fun invoke(value: A): B
isValid fun isValid(value: A): Boolean
not Negates this predicateoperator fun not(): Refined<A, B>
or Composition of either the Constraints of this predicate or the constraints of otherinfix fun <C> or(other: Refined<A, C>): Refined<A, C>
orNull Safe null construction.fun orNull(value: A): B?
plus Composition of all the Constraints of this predicate with the constraints of otheroperator fun <C> plus(other: Refined<A, C>): Refined<A, C>
require Unsafe construction.fun require(value: A): B

Inheritors

And Boolean conjunction of the left and right predicates. left and rightclass And<A, B> : Refined<A, B>
Not Boolean negation of a predicate. !predicateclass Not<A, B> : Refined<A, B>
NotZero NotZero constrains an Int to be != 0object NotZero : Refined<Int, NotZero>
Or Boolean disjunction of the left and right predicates. left or rightclass Or<A, B> : Refined<A, B>
Zero Zero constrains an Int to be == 0object Zero : Refined<Int, Zero>

Do you like Arrow?

Arrow Org
<