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

PortNumber

class PortNumber

PortNumber constrains Int to be in range of 0..65535

Safe nullable construction

import arrow.refinement.network.PortNumber

PortNumber.orNull(55555)
// PortNumber(value=55555)
PortNumber.orNull(100000)

Resolved constraints

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

Folding validation

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

Unsafe require

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

Types

Companion companion object Companion : Refined<Int, PortNumber>

Properties

value val value: Int

Do you like Arrow?

Arrow Org
<