arrow-refined-types / arrow.refinement.digests / MD5

MD5

class MD5

MD5 constrains String to be a valid hexadecimal String of length 32

Safe nullable construction

import arrow.refinement.digests.MD5

MD5.orNull("098f6bcd4621d373cade4e832627b4f6")
// 098f6bcd4621d373cade4e832627b4f6
MD5.orNull("not-md5")

Resolved constraints

MD5.constraints("098f6bcd4621d373cade4e832627b4f6")
// [(true, Expected 098f6bcd4621d373cade4e832627b4f6 to be a valid hexadecimal string), (true, Expected 098f6bcd4621d373cade4e832627b4f6 to have length 32)]
MD5.constraints("not-md5")
// [(false, Expected not-md5 to be a valid hexadecimal string), (false, Expected not-md5 to have length 32)]
MD5.isValid("098f6bcd4621d373cade4e832627b4f6")
// true
MD5.isValid("not-md5")
// false

Folding validation

MD5.fold("098f6bcd4621d373cade4e832627b4f6", { "failed: $it" }, { "success: $it" })
// success: MD5(value=098f6bcd4621d373cade4e832627b4f6)
MD5.fold("not-md5", { "failed: $it" }, { "success: $it" })
// failed: [(false, Expected not-md5 to be a valid hexadecimal string), (false, Expected not-md5 to have length 32)]

Unsafe require

MD5.require("098f6bcd4621d373cade4e832627b4f6")
// 098f6bcd4621d373cade4e832627b4f6
try { MD5.require("not-md5") } catch (e: IllegalArgumentException) { e.message }
// Expected not-md5 to be a valid hexadecimal string, Expected not-md5 to have length 32

Types

Companion companion object Companion : Refined<String, MD5>

Properties

value val value: String

Do you like Arrow?

Arrow Org
<