This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.

Positive

Positive numbers exclude zero. Because the constructor for Positive is not exported, you can be confident that if you are using a Positive, then its Positive.

type Positive number = Positive number
fromInt : Int -> Maybe (Positive Int)
fromFloat : Float -> Maybe (Positive Float)
toNum : Positive number -> number
module Positive exposing (Positive, fromInt, fromFloat, toNum)

{-|
Positive numbers exclude zero.
Because the constructor for `Positive` is not exported, you can be
confident that if you are using a `Positive`, then its `Positive`.

@docs Positive, fromInt, fromFloat, toNum
-}


{-| -}
type Positive number
    = Positive number


{-| -}
fromNum_ : comparable -> Maybe (Positive comparable)
fromNum_ x =
    if x > 0 then
        Just (Positive x)
    else
        Nothing


{-| -}
fromInt : Int -> Maybe (Positive Int)
fromInt =
    fromNum_


{-| -}
fromFloat : Float -> Maybe (Positive Float)
fromFloat =
    fromNum_


{-| -}
toNum : Positive number -> number
toNum (Positive x) =
    x