finos/morphir-elm/14.1.0

NOTE: the latest version is 22.0.2

Formerly Morgan-Stanley/morphir-elm. Search finds this package by either name.

Morphir.SDK.Validate

This module provides convenient but unsafe operations that the tooling will translate into safe operation in the runtime environment. Sample use:

type alias Input =
    { name : Maybe String
    , age : String
    }


type alias Validated =
    { name : String
    , age : Int
    }


validate : Input -> Validated
validate input =
    { name = required input.name
    , age = parse input.age
    }
required : Maybe a -> a

Indicate that a value is required without handling missing values.

required (Just 1) == 1


required Nothing -- compiles, runtime error in Elm
parse : String -> a

Indicate that the String value should be parsed into a specific type without specifying how.

Important: running this in Elm will always fail!

parse "11" + 2 -- compiles, runtime error in Elm