arrow-refined-types / arrow.refinement.network / DynamicPortNumber

DynamicPortNumber

class DynamicPortNumber

DynamicPortNumber constrains Int to be in range of 49152..65535

Safe nullable construction

import arrow.refinement.network.DynamicPortNumber

DynamicPortNumber.orNull(55555)
// DynamicPortNumber(value=55555)
DynamicPortNumber.orNull(0)

Resolved constraints

DynamicPortNumber.constraints(55555)
// [(true, 55555 should be in the closed range of 49152..65535 to be a valid dynamic port number)]
DynamicPortNumber.constraints(0)
// [(false, 0 should be in the closed range of 49152..65535 to be a valid dynamic port number)]
DynamicPortNumber.isValid(55555)
// true
DynamicPortNumber.isValid(0)
// false

Folding validation

DynamicPortNumber.fold(55555, { "failed: $it" }, { "success: $it" })
// success: DynamicPortNumber(value=55555)
DynamicPortNumber.fold(0, { "failed: $it" }, { "success: $it" })
// failed: [(false, 0 should be in the closed range of 49152..65535 to be a valid dynamic port number)]

Unsafe require

try { DynamicPortNumber.require(0) } catch (e: IllegalArgumentException) { e.message }
// 0 should be in the closed range of 49152..65535 to be a valid dynamic port number
DynamicPortNumber.require(55555)
// 55555

Types

Companion companion object Companion : Refined<Int, DynamicPortNumber>

Properties

value val value: Int

Do you like Arrow?

Arrow Org
<