Skip to content

Commit e24b9b6

Browse files
committed
Add Decode.Helpers.listWithoutFailures
1 parent 2c260cd commit e24b9b6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/Lib/Decode/Helpers.elm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ import List.Nonempty as NEL
77
import Url exposing (Url)
88

99

10+
listWithoutFailures : Decode.Decoder a -> Decode.Decoder (List a)
11+
listWithoutFailures decodeA =
12+
let
13+
decodeMaybeA =
14+
Decode.oneOf
15+
[ decodeA |> Decode.map Just
16+
, Decode.succeed Nothing
17+
]
18+
in
19+
Decode.list decodeMaybeA
20+
|> Decode.map (List.filterMap identity)
21+
22+
1023
maybeAt : List String -> Decode.Decoder b -> Decode.Decoder (Maybe b -> c) -> Decode.Decoder c
1124
maybeAt path decode =
1225
optionalAt path (Decode.map Just decode) Nothing

0 commit comments

Comments
 (0)