one type for emptiable and safe non-empty
🧩 Read about allowable state first
Emptiable ..... Never | PossiblyA 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)StackHandle 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"), ...
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 ] )emptiness-typed is already being used→ See contributing.md
typesafe-array takes it to the extreme. The possible length range is part of its type, allowing safe access for some elements