lue-bird/elm-emptiness-typed/4.1.0

NOTE: the latest version is 9.2.1

one type for emptiable and safe non-empty

emptiness typed

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

Empty ... TextFilled acts like a type-safe Maybe NonEmptyString 🌿

Stack

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

FocusList

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

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.