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, fillMap)
type TextFilled
= TextFilled Char String
first : Emptiable TextFilled Never -> Char
first =
fill >> \(TextFilled firstChar _) -> firstChar
maybeFirst :
Emptiable TextFilled possiblyOrNever
-> Emptiable Char possiblyOrNever
maybeFirst =
fillMap (filled >> first)StackHandle lists that are Possibly or Never Emptiable in one go.
Emptiable ... Never allows safe Maybe-free top, topRemove, fold (for finding the maximum etc.; some call it "fold1"), ...
import Emptiable exposing (Emptiable)
import Stack exposing (Stacked, topDown, onTopStack, onTopLay, toTopDown)
Emptiable.empty
--: Emptiable (Stacked element_) Possibly
|> onTopLay 0
--: Emptiable (Stacked number_) never_
|> onTopStack (topDown 1 [ 2, 3 ])
--: Emptiable (Stacked number_) never_
|> toTopDown
--> ( 1, [ 2, 3, 0 ] )ScrollItems rolled up on both sides of a focus
→ good fit for dynamic choice selection: tabs, playlist, ... ↑ examples
Scroll can even focus a gap Down or Up from every item.
import Linear exposing (DirectionLinear(..))
import Emptiable exposing (filled)
import Stack exposing (topDown)
import Scroll exposing (Scroll, FocusGap)
Scroll.empty
--: Scroll item_ FocusGap Possibly
|> Scroll.focusAlter (\_ -> -1 |> filled)
--: Scroll number_ FocusGap never_
|> Scroll.sideAlter
( Up, \_ -> topDown 1 [ 2, 3 ] )
--: Scroll number_ FocusGap never_
|> Scroll.toGap Up
--: Scroll number_ FocusGap Possibly
|> Scroll.focusAlter (\_ -> 0 |> filled)
--: Scroll number_ FocusGap never_
|> Scroll.toStack
--> topDown -1 [ 0, 1, 2, 3 ]→ 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.