bump 0.1.2.5
[htalkat.git] / Util.hs
blob16009f7b0b9c4ded7d004cde2f5a5c21f214cfe2
1 -- This file is part of htalkat
2 -- Copyright (C) 2021 Martin Bays <mbays@sdf.org>
3 --
4 -- This program is free software: you can redistribute it and/or modify
5 -- it under the terms of version 3 of the GNU General Public License as
6 -- published by the Free Software Foundation, or any later version.
7 --
8 -- You should have received a copy of the GNU General Public License
9 -- along with this program. If not, see http://www.gnu.org/licenses/.
11 {-# LANGUAGE Safe #-}
13 module Util where
14 import Control.Monad (unless, when)
16 -- nice tip from one joeyh:
17 whenM,unlessM,(>>?),(>>!) :: Monad m => m Bool -> m () -> m ()
18 whenM c a = c >>= flip when a
19 unlessM c a = c >>= flip unless a
20 (>>?) = whenM
21 (>>!) = unlessM
22 -- same precedence as ($), allowing e.g. foo bar >>! error $ "failed " ++ meep
23 infixr 0 >>?
24 infixr 0 >>!
26 maybeToEither :: e -> Maybe a -> Either e a
27 maybeToEither e = maybe (Left e) Right
29 eitherToMaybe :: Either e a -> Maybe a
30 eitherToMaybe (Left _) = Nothing
31 eitherToMaybe (Right a) = Just a