summaryrefslogtreecommitdiff
path: root/src/Miscellaneous.hs
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2017-01-10 01:01:24 +1100
committerJed Barber <jjbarber@y7mail.com>2017-01-10 01:01:24 +1100
commitc0d0b285cf2a6d6151e66148a022d67d46daca31 (patch)
tree231ea6c982cd98c06d535ca03f48607fc0ec5827 /src/Miscellaneous.hs
parent50adbf5cdf9ef6924c47b6738dfd6139d19a0438 (diff)
Candidate info parsing added, fixed potential bug in Counter construction
Diffstat (limited to 'src/Miscellaneous.hs')
-rw-r--r--src/Miscellaneous.hs33
1 files changed, 30 insertions, 3 deletions
diff --git a/src/Miscellaneous.hs b/src/Miscellaneous.hs
index 94e9672..de20a3d 100644
--- a/src/Miscellaneous.hs
+++ b/src/Miscellaneous.hs
@@ -1,7 +1,15 @@
module Miscellaneous(
- if'
- (?)
- ) where\
+ if',
+ (?),
+ selectFrom
+ ) where
+
+
+
+
+import Control.Monad as Con
+import qualified Data.List as List
+import qualified Data.Maybe as Maybe
@@ -17,3 +25,22 @@ infixr 1 ?
(?) = if'
+
+-- kinda functions like poor man's sql
+-- first argument is the indices of the items you want in the results
+-- second argument is index-item pairs to dictate what records are acceptable to select from
+-- third argument is the list of items that makes up the record under consideration
+-- then if the record was deemed acceptable you get the bits you wanted
+-- (note that all indices start from 1)
+selectFrom :: (Num t, Eq t, Eq a, Enum t) => [t] -> [(t,a)] -> [a] -> Maybe [a]
+selectFrom pick has from =
+ let tailFunc r i =
+ let check = List.lookup (fst i) has
+ in if (Maybe.isNothing check || Maybe.fromJust check == snd i)
+ then if (List.elem (fst i) pick)
+ then Just (r ++ [snd i])
+ else Just r
+ else Nothing
+ in Con.foldM tailFunc [] (zip [1,2..] from)
+
+