]> Git — Sourcephile - tmp/julm/arpeggigon.git/blob - src/RMCA/Auxiliary/Misc.hs
Removed debug.
[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 -- | Reversed version of '(\<$\>)'.
10 (<$$>) :: (Functor f) => f a -> (a -> b) -> f b
11 (<$$>) = flip (<$>)
12
13 -- | Reversed version of '(<$)'.
14 ($>) :: (Functor f) => f a -> b -> f b
15 ($>) = flip (<$)
16
17 -- | @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@.
18 bound :: (Ord a) => (a, a) -> a -> a
19 bound (min, max) x
20 | x < min = min
21 | x > max = max
22 | otherwise = x
23
24 fromMaybeM_ :: (Monad m) => Maybe (m ()) -> m ()
25 fromMaybeM_ = fromMaybe (return ())
26
27 safeHead :: [a] -> Maybe a
28 safeHead [] = Nothing
29 safeHead (x:_) = Just x
30
31 safeTail :: [a] -> [a]
32 safeTail [] = []
33 safeTail (_:xs) = xs
34
35 maybeToEvent :: Maybe a -> Event a
36 maybeToEvent Nothing = NoEvent
37 maybeToEvent (Just x) = Event x
38
39 eventToMaybe :: Event a -> Maybe a
40 eventToMaybe NoEvent = Nothing
41 eventToMaybe (Event x) = Just x
42
43 eventToList :: Event [a] -> [a]
44 eventToList NoEvent = []
45 eventToList (Event x) = x
46
47 -- | Generates an 'Event' if the given condition is 'True'.
48 eventIf :: Bool -> Event ()
49 eventIf b = if b then Event () else NoEvent
50
51 -- | Generates a 'Just' value if the given condition is 'True'.
52 maybeIf :: Bool -> Maybe ()
53 maybeIf b = if b then Just () else Nothing
54
55 curry3 :: ((a,b,c) -> d) -> a -> b -> c -> d
56 curry3 f a b c = f (a,b,c)
57
58 uncurry3 :: (a -> b -> c -> d) -> (a,b,c) -> d
59 uncurry3 f (a,b,c) = f a b c
60
61 curry4 :: ((a,b,c,d) -> e) -> a -> b -> c -> d -> e
62 curry4 f a b c d = f (a,b,c,d)
63
64 uncurry4 :: (a -> b -> c -> d -> e) -> (a,b,c,d) -> e
65 uncurry4 f (a,b,c,d) = f a b c d
66
67 curry5 :: ((a,b,c,d,e) -> f) -> a -> b -> c -> d -> e -> f
68 curry5 f a b c d e = f (a,b,c,d,e)
69
70 uncurry5 :: (a -> b -> c -> d -> e -> f) -> (a,b,c,d,e) -> f
71 uncurry5 f (a,b,c,d,e) = f a b c d e