]> Git — Sourcephile - tmp/julm/arpeggigon.git/blob - src/RMCA/Auxiliary/Misc.hs
Changes to make Arpeggigon compile and run with GHC 7.8.3 and base 4.7.
[tmp/julm/arpeggigon.git] / src / RMCA / Auxiliary / Misc.hs
1 module RMCA.Auxiliary.Misc where
2
3 import Data.Maybe
4 import FRP.Yampa
5
6 -- |= General functions
7
8
9 {-
10 -- | Reversed version of '(\<$\>)'.
11 (<$$>) :: (Functor f) => f a -> (a -> b) -> f b
12 (<$$>) = flip (<$>)
13
14 -- | Reversed version of '(<$)'.
15 ($>) :: (Functor f) => f a -> b -> f b
16 ($>) = flip (<$)
17 -}
18
19 -- | @bound (min,max)@ behaves like identity if the supplied value is between @min@ and @max@, otherwise it is replaced either by @min@ or by @max@.
20 bound :: (Ord a) => (a, a) -> a -> a
21 bound (min, max) x
22 | x < min = min
23 | x > max = max
24 | otherwise = x
25
26 fromMaybeM_ :: (Monad m) => Maybe (m ()) -> m ()
27 fromMaybeM_ = fromMaybe (return ())
28
29 safeHead :: [a] -> Maybe a
30 safeHead [] = Nothing
31 safeHead (x:_) = Just x
32
33 safeTail :: [a] -> [a]
34 safeTail [] = []
35 safeTail (_:xs) = xs
36
37 maybeToEvent :: Maybe a -> Event a
38 maybeToEvent Nothing = NoEvent
39 maybeToEvent (Just x) = Event x
40
41 eventToMaybe :: Event a -> Maybe a
42 eventToMaybe NoEvent = Nothing
43 eventToMaybe (Event x) = Just x
44
45 eventToList :: Event [a] -> [a]
46 eventToList NoEvent = []
47 eventToList (Event x) = x
48
49 -- | Generates an 'Event' if the given condition is 'True'.
50 eventIf :: Bool -> Event ()
51 eventIf b = if b then Event () else NoEvent
52
53 -- | Generates a 'Just' value if the given condition is 'True'.
54 maybeIf :: Bool -> Maybe ()
55 maybeIf b = if b then Just () else Nothing
56
57 curry3 :: ((a,b,c) -> d) -> a -> b -> c -> d
58 curry3 f a b c = f (a,b,c)
59
60 uncurry3 :: (a -> b -> c -> d) -> (a,b,c) -> d
61 uncurry3 f (a,b,c) = f a b c
62
63 curry4 :: ((a,b,c,d) -> e) -> a -> b -> c -> d -> e
64 curry4 f a b c d = f (a,b,c,d)
65
66 uncurry4 :: (a -> b -> c -> d -> e) -> (a,b,c,d) -> e
67 uncurry4 f (a,b,c,d) = f a b c d
68
69 curry5 :: ((a,b,c,d,e) -> f) -> a -> b -> c -> d -> e -> f
70 curry5 f a b c d e = f (a,b,c,d,e)
71
72 uncurry5 :: (a -> b -> c -> d -> e -> f) -> (a,b,c,d,e) -> f
73 uncurry5 f (a,b,c,d,e) = f a b c d e