one type for emptiable and safe non-empty
🧩 Read about allowable state first
📦 Emptiable
..... Never |
Possibly
A Maybe
value that can be made non-empty depending on what we know – an "emptiable-able" value
import Emptiable exposing (Emptiable, filled, fill)
type alias TextFilled =
{ first : Char, afterFirst : String }
first : Emptiable TextFilled Never -> Char
first =
fill >> .first
maybeFirst :
Emptiable TextFilled possiblyOrNever
-> Emptiable Char possiblyOrNever
maybeFirst =
Emptiable.map (filled >> first)
Handle lists that are
Possibly
or Never
Emptiable
in one go
Emptiable ... Never
allows safe Maybe
-free
top
, removeTop
,
fold
(for finding the maximum etc.; some call it "fold1"), ...
That's more useful than you might think.
import Linear exposing (Direction(..))
import Emptiable exposing (Emptiable)
import Stack exposing (Stacked)
Emptiable.empty
--: Emptiable (Stacked element_) Possibly
|> Stack.onTopLay 0
--: Emptiable (Stacked number_) never_
|> Stack.attach Down (Stack.topBelow 1 [ 2, 3 ])
--: Emptiable (Stacked number_) never_
|> Stack.toTopBelow
--> ( 1, [ 2, 3, 0 ] )
→ See contributing.md