This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.

Form.Validate.Pipeline

Form.Validate.Pipeline

Use the (|>) operator to build Form validators. Heavily inspired by the wonderful Json.Decode.Pipeline package.

Beginning pipelines

validate : a -> Validation e a

Begin a validation pipeline. This is a synonym for Form.Validate.succeed, intended to make things read more clearly.

import Form.Validate exposing (Validation, string, int)
import Form.Validate.Pipeline exposing (validate, with)

type alias User =
    { id : Int
    , name : String
    , email : String
    }

validateUser : Validation () User
validateUser =
    validate User
        |> with "id" int
        |> with "name" string
        |> with "email" string

Validating fields

with : String -> Validation e a -> Validation e (a -> b) -> Validation e b

Validate a field.

module Form.Validate.Pipeline exposing (validate, with)

{-|


# Form.Validate.Pipeline


Use the `(|>)` operator to build Form validators.  Heavily inspired by the wonderful [Json.Decode.Pipeline](http://package.elm-lang.org/packages/NoRedInk/elm-decode-pipeline/latest) package.


## Beginning pipelines


@docs validate


## Validating fields


@docs with




-}

import Form.Validate exposing (Validation, map2, field, succeed)


{-| Begin a validation pipeline. This is a synonym for [Form.Validate.succeed](http://package.elm-lang.org/packages/bowst/elm-form/1.0.0/Form-Validate#succeed),
intended to make things read more clearly.

    import Form.Validate exposing (Validation, string, int)
    import Form.Validate.Pipeline exposing (validate, with)

    type alias User =
        { id : Int
        , name : String
        , email : String
        }

    validateUser : Validation () User
    validateUser =
        validate User
            |> with "id" int
            |> with "name" string
            |> with "email" string
-}
validate : a -> Validation e a
validate =
    succeed


{-| Validate a field.
-}
with : String -> Validation e a -> Validation e (a -> b) -> Validation e b
with key validator wrapped =
    map2 (<|) wrapped (field key validator)