lue-bird/elm-emptiness-typed/7.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

📦 Emptiable ..... Never | Possibly

A 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)

📚 Stack

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

📜 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 or Up from every item

import Linear exposing (Direction(..))
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 ]

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