Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/Validate.elm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module Validate
, isBlank
, isInt
, isValidEmail
, preMap
, validate
)

Expand Down Expand Up @@ -57,6 +58,11 @@ module Validate
@docs all, any, firstError


# Reusing validators

@docs preMap


# Checking values directly

@docs isBlank, isInt, isValidEmail
Expand Down Expand Up @@ -220,6 +226,33 @@ ifFalse test error =



-- REUSING VALIDATORS --


{-| Reuse a validator in a larger context.

import Validate exposing (ifBlank, preMap)

type alias User =
{ name : String
}

nameValidator : Validator String String
nameValidator =
ifBlank identity
"Please enter a name"

userValidator : Validator String User
userValidator =
preMap .user nameValidator

-}
preMap : (large -> small) -> Validator error small -> Validator error large
preMap f (Validator validator) =
Validator (f >> validator)



-- COMBINING VALIDATORS --


Expand Down