lue-bird/elm-emptiness-typed/5.0.1

NOTE: the latest version is 9.2.1

one type for emptiable and safe non-empty

emptiness typed

_🗨️ 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 🌿

Stack

Handle 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 ] )

Scroll

Items 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 ]

suggestions?

→ See contributing.md

you like type-safety?

typesafe-array takes it to the extreme. The possible length range is part of its type, allowing safe access for some elements.

Scroll alternatives