-- | Helpers for dealing with formatting of Units
module Drasil.DocumentLanguage.Units where

import Language.Drasil (Sentence(S, Sy), usymb, MayHaveUnit(getUnit))

-- | Get the units, if they exist, and wrap them as a 'Sentence'. Default value is \"--\".
toSentence :: (MayHaveUnit u) => u -> Sentence
toSentence :: forall u. MayHaveUnit u => u -> Sentence
toSentence u
x = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (String -> Sentence
S String
"--") (USymb -> Sentence
Sy forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall u. HasUnitSymbol u => u -> USymb
usymb) (forall u. MayHaveUnit u => u -> Maybe UnitDefn
getUnit u
x)

-- | Similar to 'toSentence', except default value is \"Unitless\".
toSentenceUnitless :: (MayHaveUnit u) => u -> Sentence
toSentenceUnitless :: forall u. MayHaveUnit u => u -> Sentence
toSentenceUnitless u
x = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (String -> Sentence
S String
"Unitless") (USymb -> Sentence
Sy forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall u. HasUnitSymbol u => u -> USymb
usymb) (forall u. MayHaveUnit u => u -> Maybe UnitDefn
getUnit u
x)