aboutsummaryrefslogtreecommitdiffstats
path: root/app/Issue/Filter.hs
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2023-10-17 11:56:11 +0200
committerLibravatar Alexander Foremny <aforemny@posteo.de>2023-10-17 11:56:11 +0200
commitab9f65916c81fd82f05befc0679c45fe05f26531 (patch)
tree950431c14e9663712f51ac17ebe9833132664d3d /app/Issue/Filter.hs
parentb24f614f0f6aa8363b12f007a44a5d4bc41ec739 (diff)
make sort type-aware
Diffstat (limited to 'app/Issue/Filter.hs')
-rw-r--r--app/Issue/Filter.hs23
1 files changed, 2 insertions, 21 deletions
diff --git a/app/Issue/Filter.hs b/app/Issue/Filter.hs
index c30a8e2..7501e35 100644
--- a/app/Issue/Filter.hs
+++ b/app/Issue/Filter.hs
@@ -9,11 +9,10 @@ import Control.Applicative (liftA2, (<|>))
import Data.Attoparsec.Text qualified as A
import Data.Text (Text)
import Data.Text qualified as T
-import Data.Time.Calendar (Day)
import Issue (Issue (..))
import Issue.Tag (tagKey, tagValue)
+import Issue.TypedValue (castDef)
import Options.Applicative qualified as O
-import Text.Read (readMaybe)
-- TODO Revise filter negation
--
@@ -121,7 +120,7 @@ simpleFilterPredicate (ByTag k v) i = any ((&&) <$> matchKey <*> matchValue) (i.
matchKey = (==) k . tagKey
matchValue t =
case (v, tagValue t) of
- (Just (o, v'), Just w') -> cast (op o) v' w'
+ (Just (o, v'), Just w') -> castDef False (op o) v' w'
(Just _, Nothing) -> False
(Nothing, _) -> True
@@ -131,21 +130,3 @@ op (Ge) = flip (>=)
op (Gt) = flip (>)
op (Le) = flip (<=)
op (Lt) = flip (<)
-
-data Type a where
- Date :: Type Day
- Int :: Type Int
- String :: Type Text
-
-cast :: (forall a. Ord a => a -> a -> Bool) -> (Text -> Text -> Bool)
-cast eq x y
- | Just x' <- castTo Date x, Just y' <- castTo Date y = eq x' y'
- | Just _ <- castTo Date x, Nothing <- castTo Date y = False
- | Just x' <- castTo Int x, Just y' <- castTo Int y = eq x' y'
- | Just _ <- castTo Int x, Nothing <- castTo Int y = False
- | otherwise = eq x y
-
-castTo :: Type a -> Text -> Maybe a
-castTo Date = readMaybe . T.unpack
-castTo Int = readMaybe . T.unpack
-castTo String = Just