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

NonSystemPortNumber

class NonSystemPortNumber

NonSystemPortNumber constrains Int to be in range of 1024..65535

Safe nullable construction

import arrow.refinement.network.NonSystemPortNumber

NonSystemPortNumber.orNull(55555)
// NonSystemPortNumber(value=55555)
NonSystemPortNumber.orNull(22)

Resolved constraints

NonSystemPortNumber.constraints(55555)
// [(true, 55555 should be in the closed range of 1024..65535 to be a valid system port number)]
NonSystemPortNumber.constraints(22)
// [(false, 22 should be in the closed range of 1024..65535 to be a valid system port number)]
NonSystemPortNumber.isValid(55555)
// true
NonSystemPortNumber.isValid(22)
// false

Folding validation

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

Unsafe require

try { NonSystemPortNumber.require(22) } catch (e: IllegalArgumentException) { e.message }
// 22 should be in the closed range of 1024..65535 to be a valid system port number
NonSystemPortNumber.require(55555)
// 55555

Types

Companion companion object Companion : Refined<Int, NonSystemPortNumber>

Properties

value val value: Int

Do you like Arrow?

Arrow Org
<