1 module RMCA.Auxiliary.Misc where
6 -- |= General functions
10 -- | Reversed version of '(\<$\>)'.
11 (<$$>) :: (Functor f) => f a -> (a -> b) -> f b
14 -- | Reversed version of '(<$)'.
15 ($>) :: (Functor f) => f a -> b -> f b
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
26 fromMaybeM_ :: (Monad m) => Maybe (m ()) -> m ()
27 fromMaybeM_ = fromMaybe (return ())
29 safeHead :: [a] -> Maybe a
31 safeHead (x:_) = Just x
33 safeTail :: [a] -> [a]
37 maybeToEvent :: Maybe a -> Event a
38 maybeToEvent Nothing = NoEvent
39 maybeToEvent (Just x) = Event x
41 eventToMaybe :: Event a -> Maybe a
42 eventToMaybe NoEvent = Nothing
43 eventToMaybe (Event x) = Just x
45 eventToList :: Event [a] -> [a]
46 eventToList NoEvent = []
47 eventToList (Event x) = x
49 curry3 :: ((a,b,c) -> d) -> a -> b -> c -> d
50 curry3 f a b c = f (a,b,c)
52 uncurry3 :: (a -> b -> c -> d) -> (a,b,c) -> d
53 uncurry3 f (a,b,c) = f a b c
55 curry4 :: ((a,b,c,d) -> e) -> a -> b -> c -> d -> e
56 curry4 f a b c d = f (a,b,c,d)
58 uncurry4 :: (a -> b -> c -> d -> e) -> (a,b,c,d) -> e
59 uncurry4 f (a,b,c,d) = f a b c d
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)
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