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

SHA1

class SHA1

SHA1 constrains String to be a valid hexadecimal String of length 40

Safe nullable construction

import arrow.refinement.digests.SHA1

SHA1.orNull("a94a8fe5ccb19ba61c4c0873d391e987982fbbd3")
// a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
SHA1.orNull("not-sha1")

Resolved constraints

SHA1.constraints("a94a8fe5ccb19ba61c4c0873d391e987982fbbd3")
// [(true, Expected a94a8fe5ccb19ba61c4c0873d391e987982fbbd3 to be a valid hexadecimal string), (true, Expected a94a8fe5ccb19ba61c4c0873d391e987982fbbd3 to have length 40)]
SHA1.constraints("not-sha1")
// [(false, Expected not-sha1 to be a valid hexadecimal string), (false, Expected not-sha1 to have length 40)]
SHA1.isValid("a94a8fe5ccb19ba61c4c0873d391e987982fbbd3")
// true
SHA1.isValid("not-sha1")
// false

Folding validation

SHA1.fold("a94a8fe5ccb19ba61c4c0873d391e987982fbbd3", { "failed: $it" }, { "success: $it" })
// success: SHA1(value=a94a8fe5ccb19ba61c4c0873d391e987982fbbd3)
SHA1.fold("not-sha1", { "failed: $it" }, { "success: $it" })
// failed: [(false, Expected not-sha1 to be a valid hexadecimal string), (false, Expected not-sha1 to have length 40)]

Unsafe require

SHA1.require("a94a8fe5ccb19ba61c4c0873d391e987982fbbd3")
// a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
try { SHA1.require("not-sha1") } catch (e: IllegalArgumentException) { e.message }
// Expected not-sha1 to be a valid hexadecimal string, Expected not-sha1 to have length 40

Types

Companion companion object Companion : Refined<String, SHA1>

Properties

value val value: String

Do you like Arrow?

Arrow Org
<