hmt-0.15: Haskell Music Theory

Safe HaskellSafe-Inferred
LanguageHaskell98

Music.Theory.Maybe

Description

Extensions to Data.Maybe.

Synopsis

Documentation

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

filter_maybe :: (a -> Bool) -> [a] -> [Maybe a] Source

Variant of filter that retains Nothing as a placeholder for removed elements.

filter_maybe even [1..4] == [Nothing,Just 2,Nothing,Just 4]