one type for emptiable and safe non-empty
_🗨️ Read about allowable state first _
Hand . . . Never | Possibly Empty
is a convenience layer for an emptiable-able value:
import Hand exposing (Hand, Empty, filled, fill, fillMap)
type TextFilled
= TextFilled Char String
first : Hand TextFilled Never Empty -> Char
first =
fill >> \(TextFilled firstChar _) -> firstChar
fillMap (filled >> first)
--: Hand TextFilled possiblyOrNever Empty
--: -> Hand Char possiblyOrNever Empty→ Hand TextFilled Never|Possibly Empty is like a type-safe Maybe TextFilled 🌿
StackHandle lists that are Possibly or Never Empty in one go.
Never Empty allows safe Maybe-free top, topRemove, fold (useful for finding the maximum, etc. some call it "fold1"), ...
import Hand exposing (Hand, Empty)
import Stack exposing (Stacked, topDown, onTopStack, onTopLay, toTopDown)
Stack.only 0
|> onTopStack (topDown 1 [ 2, 3 ])
--: Hand (Stacked number_) never_ Empty
|> onTopLay 5
--: Hand (Stacked number_) never_ Empty
|> toTopDown
--> ( 5, [ 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 and Up every item.
import Linear exposing (DirectionLinear(..))
import Hand exposing (filled)
import Stack exposing (topDown)
import Scroll exposing (Scroll, FocusGap)
Scroll.empty
--: Scroll item_ Possibly FocusGap
|> Scroll.focusAlter (\_ -> -1 |> filled)
--: Scroll number_ never_ FocusGap
|> Scroll.sideAlter
( Up, \_ -> topDown 1 [ 2, 3 ] )
--: Scroll number_ never_ FocusGap
|> Scroll.toGap Up
--: Scroll number_ Possibly FocusGap
|> Scroll.focusAlter (\_ -> 0 |> filled)
--: Scroll number_ never_ FocusGap
|> 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.
Scroll alternativesmapOver, focusDrag, mapIndexed, toNonEmptyList, sideAlter (so no squeezing in multiple items, ...)List.NonEmpty.Zipper
complete; cluttered (for example update & map); some unintuitive namesfocusWheremapOvermapOver, sideAlter (so no squeezing in multiple items, ...)focusDrag, mapOver, mapIndexed, toNonEmptyListside, ...focusDrag, mapIndexed, toNonEmptyList, sideAlter (so no squeezing in multiple items, ...)Reference.List
only overList, sides impossible to access & alter