Morph
for an elm/core
Maybe content
value : Value.Morph.Internal.MorphValue element -> Value.Morph.Internal.MorphValue (Maybe element)
Maybe
MorphValue
toJust : MorphIndependently (Maybe narrowContent -> Result Morph.Error narrowContent) (broadContent -> Maybe broadContent)
Just content
succeeds with the content
, Nothing
fails.
import Morph
import Char.Morph
Just 'Y'
|> Morph.toNarrow
(Char.Morph.only 'Y'
|> Morph.over Maybe.Morph.toJust
)
--> Ok ()
row : MorphRow contentNarrow broadElement -> MorphRow (Maybe contentNarrow) broadElement
Try to Morph
a value and return it as a Just
.
If something fails, go back to where you started and return Nothing
ℹ️ Equivalent regular expression:
?
import AToZ
import AToZ.Morph
import List.Morph
import Morph
-- maybe we get `Just` a letter
"a"
|> Morph.toNarrow
(Maybe.Morph.row (AToZ.Morph.lowerChar |> Morph.one)
|> Morph.rowFinish
|> Morph.over List.Morph.string
)
--> Ok (Just AToZ.A)
-- maybe we get `Nothing`
""
|> Morph.toNarrow
(Maybe.Morph.row (AToZ.Morph.char |> Morph.one)
|> Morph.rowFinish
|> Morph.over List.Morph.string
)
--> Ok Nothing