mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-27 05:44:17 +03:00
Add withFallback helper.
This commit is contained in:
parent
d93bb49e89
commit
dfe46878af
@ -1,4 +1,4 @@
|
||||
module Validation exposing (Validation(..), andMap, andThen, fail, fromMaybe, fromResult, map, map2, parseWithError, succeed, withError, withErrorIf, withField)
|
||||
module Validation exposing (Validation(..), andMap, andThen, fail, fromMaybe, fromResult, map, map2, parseWithError, succeed, withError, withErrorIf, withFallback, withField)
|
||||
|
||||
import Dict exposing (Dict)
|
||||
|
||||
@ -12,6 +12,16 @@ succeed parsed =
|
||||
Validation ( Just parsed, Dict.empty )
|
||||
|
||||
|
||||
withFallback : parsed -> Validation error parsed -> Validation error parsed
|
||||
withFallback parsed (Validation ( maybeParsed, errors )) =
|
||||
Validation
|
||||
( maybeParsed
|
||||
|> Maybe.withDefault parsed
|
||||
|> Just
|
||||
, errors
|
||||
)
|
||||
|
||||
|
||||
parseWithError : parsed -> ( String, error ) -> Validation error parsed
|
||||
parseWithError parsed ( key, error ) =
|
||||
Validation ( Just parsed, Dict.singleton key [ error ] )
|
||||
|
Loading…
Reference in New Issue
Block a user