Morph
for an elm/core
String
each : Morph.OneToOne Char Char -> MorphOrError String String error_
Morph.OneToOne
each Char
in a String
For fallible transformations etc,
morph to other structures (but generic ones) like a list first
and use its each
morph.
only : String -> MorphRow () Char
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
--> Nothing
See sequenceMap
, broadSequenceMap
to control what to morph for each Char
.
list : MorphOrError String (List Char) error_
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
)
stack : MorphOrError String (Emptiable (Stacked Char) Possibly) error_
Morph.OneToOne
from a
stack of Char
s.
import Stack
import Morph
Stack.topBelow '0' [ '1', '2' ]
|> Morph.mapTo String.Morph.stack
--> "012"
array : MorphOrError String (Array Char) error_
Morph.OneToOne
from an Array Char
import Array
import Morph
Array.fromList [ '0', '1', '2', '3' ]
|> Morph.mapTo String.Morph.array
--> "0123"
arraySized : MorphIndependently (ArraySized Char narrowRange_ -> Result error_ String) (String -> ArraySized Char (N.Min (N.Up0 broadX_)))
Morph.OneToOne
from an
ArraySized
of Char
s
import ArraySized
import Morph
ArraySized.l4 '0' '1' '2' '3'
|> Morph.mapTo String.Morph.arraySized
--> "0123"
Inverse of ArraySized.Morph.string
value : Value.Morph.Internal.MorphValue String
String
MorphValue
sequenceMap : (Char -> MorphRow narrowElement broadElement) -> String -> MorphRow (List narrowElement) broadElement
From the chars in a given String
,
create MorphRow
s
that will be run in the same order, one after the other.
More details → List.Morph.sequenceMap
broadSequenceMap : (Char -> MorphRow () broadElement) -> String -> MorphRow () broadElement
Match broad MorphRow
s
(those that can always produce the same broad value)
based on given input elements in sequence.
More details → List.Morph.broadSequenceMap