]> Git — Sourcephile - tmp/julm/arpeggigon.git/blob - src/RMCA/Auxiliary/Misc.hs
Add a warning about Jack in the README.
[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 curry3 :: ((a,b,c) -> d) -> a -> b -> c -> d
50 curry3 f a b c = f (a,b,c)
51
52 uncurry3 :: (a -> b -> c -> d) -> (a,b,c) -> d
53 uncurry3 f (a,b,c) = f a b c
54
55 curry4 :: ((a,b,c,d) -> e) -> a -> b -> c -> d -> e
56 curry4 f a b c d = f (a,b,c,d)
57
58 uncurry4 :: (a -> b -> c -> d -> e) -> (a,b,c,d) -> e
59 uncurry4 f (a,b,c,d) = f a b c d
60
61 curry5 :: ((a,b,c,d,e) -> f) -> a -> b -> c -> d -> e -> f
62 curry5 f a b c d e = f (a,b,c,d,e)
63
64 uncurry5 :: (a -> b -> c -> d -> e -> f) -> (a,b,c,d,e) -> f
65 uncurry5 f (a,b,c,d,e) = f a b c d e