one type for emptiable and safe non-empty
_🗨️ Read about allowable state first _
Fillable.Empty is a convenience layer for an optional-able value
where a type argument that's either Never or Possibly
is attached to its Empty variant:
import Fillable exposing (Empty, filled, filling)
type alias TextFilled =
( Char, String )
first : Empty Never TextFilled -> Char
first =
filling >> \( headChar, _ ) -> headChar
Fillable.map (filled >> first)
--: Empty possiblyOrNever TextFilled
--: -> Empty possiblyOrNever CharEmpty ... TextFilled acts like a type-safe Maybe NonEmptyString 🌿
StackHandle lists that are Empty Possibly or Never in one go.
Empty Never <some stack type> allows safe Maybe-free top, removeTop, fold (useful for finding the maximum, etc. some call it "fold1"), ...
import Fillable exposing (Empty)
import Stack exposing (StackFilled, topAndBelow, stackTypedOnTop, addOnTop, toTopAndBelow)
Fillable.empty
|> stackTypedOnTop
(topAndBelow 1 [ 2, 3 ])
-- Empty never_ (StackFilled number_)
|> addOnTop 5 -- Empty never_ (StackFilled number_)
|> toTopAndBelow
--> ( 5, [ 1, 2, 3 ] )FocusListA list zipper that can also focus before and after every element.
import FocusList exposing (ListFocusingHole)
FocusList.empty -- ListFocusingHole Possibly item_
|> FocusList.plug 5 -- ListFocusingHole never_ number_
|> FocusList.append [ 1, 2, 3 ]
-- ListFocusingHole never_ number_
|> FocusList.nextHole -- ListFocusingHole Possibly number_
|> FocusList.toList
--> [ 5, 1, 2, 3 ]= zwilias/elm-holey-zipper with a type-safe implementation using Fillable.Empty and other tweaks.
→ 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.