hmt-base-0.20: Haskell Music Theory Base
Safe HaskellSafe-Inferred
LanguageHaskell2010

Music.Theory.Maybe

Description

Extensions to Data.Maybe.

Synopsis

Documentation

from_just :: String -> Maybe a -> a Source #

Variant with error text.

maybe_unzip :: [Maybe (a, b)] -> ([Maybe a], [Maybe b]) Source #

Variant of unzip.

let r = ([Just 1,Nothing,Just 3],[Just 'a',Nothing,Just 'c'])
in maybe_unzip [Just (1,'a'),Nothing,Just (3,'c')] == r

maybe_latch :: a -> [Maybe a] -> [a] Source #

Replace Nothing elements with last Just value. This does not alter the length of the list.

maybe_latch 1 [Nothing,Just 2,Nothing,Just 4] == [1,2,2,4]

maybe_latch1 :: [Maybe a] -> [a] Source #

Variant requiring initial value is not Nothing.

maybe_latch1 [Just 1,Nothing,Nothing,Just 4] == [1,1,1,4]

maybe_map :: (a -> b) -> [Maybe a] -> [Maybe b] Source #

map of fmap.

maybe_map negate [Nothing,Just 2] == [Nothing,Just (-2)]

maybe_eq_by :: (t -> u -> Bool) -> Maybe t -> Maybe u -> Bool Source #

If either is Nothing then False, else eq of values.

maybe_join' :: (s -> t) -> (s -> s -> t) -> Maybe s -> Maybe s -> Maybe t Source #

Join two values, either of which may be missing.

maybe_join :: (t -> t -> t) -> Maybe t -> Maybe t -> Maybe t Source #

maybe_predicate :: (a -> Bool) -> Maybe a -> Maybe a Source #

Apply predicate inside Maybe.

maybe_predicate even (Just 3) == Nothing

maybe_filter :: (a -> Bool) -> [Maybe a] -> [Maybe a] Source #

map of maybe_predicate.

let r = [Nothing,Nothing,Nothing,Just 4]
in maybe_filter even [Just 1,Nothing,Nothing,Just 4] == r

all_just :: [Maybe a] -> Maybe [a] Source #

Variant of catMaybes. If all elements of the list are Just a, then gives Just [a] else gives Nothing.

all_just (map Just [1..3]) == Just [1..3]
all_just [Just 1,Nothing,Just 3] == Nothing