An option-able value.
import Fillable exposing (Empty)
import Stack exposing (StackFilled)
filling : Empty Never filling -> filling
top : Empty Never (StackFilled element) -> elementimport Fillable exposing (Empty)
import Stack exposing (StackFilled)
type alias Model =
WithoutConstructorFunction
{ searchKeyWords : Empty Never (StackFilled String)
}
type alias WithoutConstructorFunction record =
recordwhere WithoutConstructorFunction stops the compiler from creating a positional constructor function for Model.
Insert joke about life here.
empty
|> Fillable.map (\x -> x / 0)
--> emptyA Fillable.Empty that certainly exists, allowing type-safe extraction.
import Fillable exposing (filled, filling)
filled "Bami" |> filling
--> "Bami"Convert a Maybe to a Fillable.Empty.
Change the possibly Filled value based on its current value:
import Fillable exposing (filled)
filled -3 |> Fillable.map abs
--> filled 3
Fillable.empty |> Fillable.map abs
--> Fillable.emptyIf all the arguments exist, combine them using a given function.
import Fillable exposing (filled, empty)
Fillable.map2 (+) (filled 3) (filled 4) --> filled 7
Fillable.map2 (+) (filled 3) empty --> empty
Fillable.map2 (+) empty (filled 4) --> emptyChain together operations that may return empty.
If the argument Fillable.Empty Never Empty,
a given function takes its filling
and returns a new possibly empty value.
Some call it flatMap.
emptiableString
|> Fillable.andThen parse
|> Fillable.andThen extraValidation
parse : ( Char, String ) -> Empty Possibly Parsed
extraValidation : Parsed -> Empty Possibly ParsedSafely extracts the value from an Empty Never.
import Fillable exposing (Empty, filled, filling)
filled (filled (filled "Bami"))
|> filling
|> filling
|> filling
--> "Bami"
first : Empty Never ( first, others_ ) -> first
first =
filling >> Tuple.firstLazily use a fallback value if the Fillable.Empty empty.
import Possibly exposing (Possibly(..))
import Fillable exposing (toFillingOrIfEmpty)
import Dict
Dict.empty
|> Dict.get "Hannah"
|> Fillable.fromMaybe
|> toFillingOrIfEmpty (\_ -> "unknown")
--> "unknown"
filling =
toFillingOrIfEmpty neverConvert to a Maybe.
Don't try to use this prematurely. Keeping type information as long as possible is always a win.
Change the possiblyOrNever type.
Empty PossiblyAn Empty possiblyOrNever can't be used as Empty Possibly
import Fillable exposing (Empty)
import Possibly exposing (Possibly)
import Stack exposing (StackFilled)
type alias Log =
Empty Possibly (StackFilled String)
fromStack : Empty possiblyOrNever_ (StackFilled String) -> Log
fromStack stackFilled =
stackFilled
--: `possiblyOrNever_` but we need `Possibly`
|> Fillable.adaptType (always Possible)Empty NeverThe Empty Never can't be unified with Possibly or a type variable
import Fillable exposing (Empty)
import Stack exposing (StackFilled)
theShorter :
Empty Never (StackFilled element)
-> Empty possiblyOrNever (StackFilled element)
-> Empty possiblyOrNever (StackFilled element)
theShorter aStack bStack =
if Stack.length bStack > Stack.length aStack then
bStack
else
--: `Never` but we need `possiblyOrNever`
aStackto make both branches return possiblyOrNever, use
aStack |> Fillable.adaptType never
Like
Maybe, but able to know at type-level whetherEmptyis possible.Fillable.Emptyalone probably won't be that useful, but it can make data structures type-safely non-emptiable:Go take a look at all the data structures in this package.