ljuglaret/fraction/2.0.1

NOTE: the latest version is 2.0.3

Fractions

Allows manipulation of fractions : simplify, add two fractions, create a fraction, access the numerator and denominator.

How to use this package

Create Fractions

f1 : Maybe Fraction
f1 = createFraction(17,15)
-- Just (Fraction { denominator = 15, numerator = 17 })

f2 : Maybe Fraction
f2 = createFraction(17,0)
-- Nothing : Maybe Fraction

Add two fractions and simplify

s : Maybe Fraction
s = f1 |> (Maybe.andThen (\m ->
        f2 |> (Maybe.andThen (\m2 ->
            Just (simplify (addition m m2))))))

Access the denominator and numerator

a =  f1 |> (Maybe.andThen (\m -> Just (getNumerator m)))
b =  f1 |> (Maybe.andThen (\m -> Just (getdenominator m)))
-- a = Just 17
-- b = Just 15