aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/Utils.hs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/src/Utils.hs')
-rw-r--r--compiler/src/Utils.hs49
1 files changed, 49 insertions, 0 deletions
diff --git a/compiler/src/Utils.hs b/compiler/src/Utils.hs
new file mode 100644
index 0000000..794382c
--- /dev/null
+++ b/compiler/src/Utils.hs
@@ -0,0 +1,49 @@
1-- ldgallery - A static generator which turns a collection of tagged
2-- pictures into a searchable web gallery.
3--
4-- Copyright (C) 2019 Pacien TRAN-GIRARD
5--
6-- This program is free software: you can redistribute it and/or modify
7-- it under the terms of the GNU Affero General Public License as
8-- published by the Free Software Foundation, either version 3 of the
9-- License, or (at your option) any later version.
10--
11-- This program is distributed in the hope that it will be useful,
12-- but WITHOUT ANY WARRANTY; without even the implied warranty of
13-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14-- GNU Affero General Public License for more details.
15--
16-- You should have received a copy of the GNU Affero General Public License
17-- along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19
20module Utils
21 ( conj, neg
22 , unique
23 , passthrough
24 ) where
25
26
27import qualified Data.List
28import qualified Data.Set
29
30
31-- predicates
32
33conj :: (a -> Bool) -> (a -> Bool) -> a -> Bool
34conj p q x = (p x) && (q x)
35
36neg :: (a -> Bool) -> a -> Bool
37neg p x = not (p x)
38
39
40-- lists
41
42unique :: Ord a => [a] -> [a]
43unique = Data.Set.toList . Data.Set.fromList
44
45
46-- monads
47
48passthrough :: Monad m => (a -> m b) -> a -> m a
49passthrough f a = return a >>= f >>= \_ -> return a