Add Decode.mapResult

This commit is contained in:
Ayaz Hafiz 2022-10-18 14:39:35 -05:00
parent bb8888b115
commit e08b613047
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
2 changed files with 5 additions and 0 deletions

View file

@ -27,6 +27,7 @@ interface Decode
decodeWith, decodeWith,
fromBytesPartial, fromBytesPartial,
fromBytes, fromBytes,
mapResult,
] ]
imports [ imports [
List, List,
@ -96,3 +97,6 @@ fromBytes = \bytes, fmt ->
Err TooShort -> Err TooShort Err TooShort -> Err TooShort
else else
Err (Leftover rest) Err (Leftover rest)
mapResult : DecodeResult a, (a -> b) -> DecodeResult b
mapResult = \{result, rest}, mapper -> {result: Result.map result mapper, rest}

View file

@ -1518,6 +1518,7 @@ define_builtins! {
24 DECODE_DECODE_WITH: "decodeWith" 24 DECODE_DECODE_WITH: "decodeWith"
25 DECODE_FROM_BYTES_PARTIAL: "fromBytesPartial" 25 DECODE_FROM_BYTES_PARTIAL: "fromBytesPartial"
26 DECODE_FROM_BYTES: "fromBytes" 26 DECODE_FROM_BYTES: "fromBytes"
27 DECODE_MAP_RESULT: "mapResult"
} }
13 HASH: "Hash" => { 13 HASH: "Hash" => {
0 HASH_HASH_ABILITY: "Hash" exposed_type=true 0 HASH_HASH_ABILITY: "Hash" exposed_type=true