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

SystemPortNumber

class SystemPortNumber

SystemPortNumber constrains Int to be in range of 0..1023

Safe nullable construction

import arrow.refinement.network.SystemPortNumber

SystemPortNumber.orNull(1000)
// SystemPortNumber(value=1000)
SystemPortNumber.orNull(100000)

Resolved constraints

SystemPortNumber.constraints(1000)
// [(true, 1000 should be in the closed range of 0..1023 to be a valid system port number)]
SystemPortNumber.constraints(100000)
// [(false, 100000 should be in the closed range of 0..1023 to be a valid system port number)]
SystemPortNumber.isValid(1000)
// true
SystemPortNumber.isValid(100000)
// false

Folding validation

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

Unsafe require

try { SystemPortNumber.require(100000) } catch (e: IllegalArgumentException) { e.message }
// 100000 should be in the closed range of 0..1023 to be a valid system port number
SystemPortNumber.require(1000)
// 1000

Types

Companion companion object Companion : Refined<Int, SystemPortNumber>

Properties

value val value: Int

Do you like Arrow?

Arrow Org
<