lue-bird/elm-morph/1.1.0

NOTE: the latest version is 3.0.1

Stack.Morph

Morph a Stack

alter

MorphIndependently
(beforeToNarrow -> Result (ErrorWithDeadEnd deadEnd) narrow)
(beforeToBroad -> broad)
-> MorphIndependently
( Emptiable
(Stacked beforeToNarrow)
broadEmptiablePossiblyOrNever
-> Result
(ErrorWithDeadEnd deadEnd)
(Emptiable (Stacked narrow) broadEmptiablePossiblyOrNever)
)
( Emptiable (Stacked beforeToBroad) narrowPossiblyOrNever
-> Emptiable (Stacked broad) narrowPossiblyOrNever
)

Morph all stacked elements

If the given Morph is OneToOne, each will also be a OneToOne

transform

MorphIndependently
( List broadElement
-> Result error_ (Emptiable (Stacked broadElement) Possibly)
)
( Emptiable (Stacked narrowElement) Possibly
-> List narrowElement
)

Morph.OneToOne from a List.

import Stack
import Morph


[ 0, 12, 3 ]
    |> Morph.mapTo Stack.Morph.list
--> Stack.topBelow 0 [ 12, 3 ]
--: Emptiable (Stacked Int) Possibly

Inverse of List.Morph.stack

MorphIndependently
( Array broadElement
-> Result error_ (Emptiable (Stacked broadElement) Possibly)
)
( Emptiable (Stacked narrowElement) Possibly
-> Array narrowElement
)

Morph.OneToOne from an Array.

import Stack
import Array
import Morph


Array.fromList [ 0, 12, 3 ]
    |> Morph.mapTo Stack.Morph.array
--> Stack.topBelow 0 [ 12, 3 ]
--: Emptiable (Stacked Int) Possibly

Inverse of Array.Morph.stack

MorphIndependently
( ArraySized
narrowElement
(In (On (N0OrAdd1 narrowPossiblyOrNever minFrom1_)) max_)
-> Result
error_
(Emptiable (Stacked narrowElement) narrowPossiblyOrNever)
)
( Emptiable (Stacked broadElement) broadPossiblyOrNever
-> ArraySized
broadElement
(Min (On (N0OrAdd1 broadPossiblyOrNever N0)))
)

Morph.OneToOne from an ArraySized

import ArraySized
import Morph
import Stack


ArraySized.l4 0 1 2 3
    |> Morph.mapTo Stack.Morph.arraySized
--> Stack.topBelow 0 [ 1, 2, 3 ]

Inverse of ArraySized.Morph.stack

string : MorphOrError (Emptiable (Stacked Char) Possibly) String error_

Morph.OneToOne from a String to a stack of Chars.

import Stack
import Morph


"012" |> Morph.mapTo Stack.Morph.string
--> Stack.fromList [ '0', '1', '2' ]

Inverse of String.Morph.stack