Morph for an elm/core String
Match a specific given String and nothing else.
This is case sensitive.
import Morph
import List.Morph
-- match an exact text
"abc"
|> Morph.toNarrow
(String.Morph.only "abc" |> Morph.rowFinish |> Morph.over List.Morph.string)
--> Ok ()
-- case sensitive
"abC"
|> Morph.toNarrow
(String.Morph.only "abc" |> Morph.rowFinish |> Morph.over List.Morph.string)
|> Result.toMaybe
--> Nothing
-- if there is still input remaining, fail
"abcdef"
|> Morph.toNarrow
(String.Morph.only "abc" |> Morph.rowFinish |> Morph.over List.Morph.string)
|> Result.toMaybe
--> NothingSee sequenceMap, broadSequenceMap to control what to morph for each Char.
Morph.OneToOne from a List Char.
import Morph
[ '0', '1', '2', '3' ] |> Morph.mapTo String.Morph.list
--> "0123"
"0123" |> Morph.toBroad String.Morph.list
--> [ '0', '1', '2', '3' ]To use a MorphRow ... Char with a String,
use Morph.toNarrow/toBroad
with
yourData
|> Morph.toNarrowOrBroad
(yourMorphRow
|> Morph.rowFinish
|> Morph.over String.Morph.List
)Morph.OneToOne from a
stack of Chars.
import Stack
import Morph
Stack.topBelow '0' [ '1', '2' ]
|> Morph.mapTo String.Morph.stack
--> "012"Morph.OneToOne from an Array Char
import Array
import Morph
Array.fromList [ '0', '1', '2', '3' ]
|> Morph.mapTo String.Morph.array
--> "0123"Morph.OneToOne from an
ArraySized of Chars
import ArraySized
import Morph
ArraySized.l4 '0' '1' '2' '3'
|> Morph.mapTo String.Morph.arraySized
--> "0123"String MorphValue
From the chars in a given String,
create MorphRows
that will be run in the same order, one after the other.
More details → List.Morph.sequenceMap
Match broad MorphRows
(those that can always produce the same broad value)
based on given input elements in sequence.
More details → List.Morph.broadSequenceMap
Morph.OneToOneeachCharin aStringFor fallible transformations etc, morph to other structures (but generic ones) like a list first and use its
eachmorph.