1 module RMCA.Auxiliary.Misc where
6 -- |= General functions
9 -- | Reversed version of '(\<$\>)'.
10 (<$$>) :: (Functor f) => f a -> (a -> b) -> f b
13 -- | Reversed version of '(<$)'.
14 ($>) :: (Functor f) => f a -> b -> f b
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
24 fromMaybeM_ :: (Monad m) => Maybe (m ()) -> m ()
25 fromMaybeM_ = fromMaybe (return ())
27 safeHead :: [a] -> Maybe a
29 safeHead (x:_) = Just x
31 safeTail :: [a] -> [a]
35 maybeToEvent :: Maybe a -> Event a
36 maybeToEvent Nothing = NoEvent
37 maybeToEvent (Just x) = Event x
39 eventToMaybe :: Event a -> Maybe a
40 eventToMaybe NoEvent = Nothing
41 eventToMaybe (Event x) = Just x
43 eventToList :: Event [a] -> [a]
44 eventToList NoEvent = []
45 eventToList (Event x) = x
47 -- | Generates an 'Event' if the given condition is 'True'.
48 eventIf :: Bool -> Event ()
49 eventIf b = if b then Event () else NoEvent
51 -- | Generates a 'Just' value if the given condition is 'True'.
52 maybeIf :: Bool -> Maybe ()
53 maybeIf b = if b then Just () else Nothing
55 curry3 :: ((a,b,c) -> d) -> a -> b -> c -> d
56 curry3 f a b c = f (a,b,c)
58 uncurry3 :: (a -> b -> c -> d) -> (a,b,c) -> d
59 uncurry3 f (a,b,c) = f a b c
61 curry4 :: ((a,b,c,d) -> e) -> a -> b -> c -> d -> e
62 curry4 f a b c d = f (a,b,c,d)
64 uncurry4 :: (a -> b -> c -> d -> e) -> (a,b,c,d) -> e
65 uncurry4 f (a,b,c,d) = f a b c d
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)
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