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

UserPortNumber

class UserPortNumber

UserPortNumber constrains Int to be in range of 1024..49151

Safe nullable construction

import arrow.refinement.network.UserPortNumber

UserPortNumber.orNull(2000)
// UserPortNumber(value=2000)
UserPortNumber.orNull(100000)

Resolved constraints

UserPortNumber.constraints(2000)
// [(true, 2000 should be in the closed range of 1024..49151 to be a valid user port number)]
UserPortNumber.constraints(100000)
// [(false, 100000 should be in the closed range of 1024..49151 to be a valid user port number)]
UserPortNumber.isValid(2000)
// true
UserPortNumber.isValid(100000)
// false

Folding validation

UserPortNumber.fold(2000, { "failed: $it" }, { "success: $it" })
// success: UserPortNumber(value=2000)
UserPortNumber.fold(100000, { "failed: $it" }, { "success: $it" })
// failed: [(false, 100000 should be in the closed range of 1024..49151 to be a valid user port number)]

Unsafe require

try { UserPortNumber.require(100000) } catch (e: IllegalArgumentException) { e.message }
// 100000 should be in the closed range of 1024..49151 to be a valid user port number
UserPortNumber.require(2000)
// 2000

Types

Companion companion object Companion : Refined<Int, UserPortNumber>

Properties

value val value: Int

Do you like Arrow?

Arrow Org
<