{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE NoRebindableSyntax #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
module Duckling.Ordinal.Types where
import Control.DeepSeq
import Data.Aeson
import Data.Hashable
import Data.Text (Text)
import GHC.Generics
import Prelude
import Duckling.Resolve (Resolve(..))
newtype OrdinalData = OrdinalData { OrdinalData -> Int
value :: Int }
deriving (OrdinalData -> OrdinalData -> Bool
(OrdinalData -> OrdinalData -> Bool)
-> (OrdinalData -> OrdinalData -> Bool) -> Eq OrdinalData
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OrdinalData -> OrdinalData -> Bool
$c/= :: OrdinalData -> OrdinalData -> Bool
== :: OrdinalData -> OrdinalData -> Bool
$c== :: OrdinalData -> OrdinalData -> Bool
Eq, (forall x. OrdinalData -> Rep OrdinalData x)
-> (forall x. Rep OrdinalData x -> OrdinalData)
-> Generic OrdinalData
forall x. Rep OrdinalData x -> OrdinalData
forall x. OrdinalData -> Rep OrdinalData x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep OrdinalData x -> OrdinalData
$cfrom :: forall x. OrdinalData -> Rep OrdinalData x
Generic, Int -> OrdinalData -> Int
OrdinalData -> Int
(Int -> OrdinalData -> Int)
-> (OrdinalData -> Int) -> Hashable OrdinalData
forall a. (Int -> a -> Int) -> (a -> Int) -> Hashable a
hash :: OrdinalData -> Int
$chash :: OrdinalData -> Int
hashWithSalt :: Int -> OrdinalData -> Int
$chashWithSalt :: Int -> OrdinalData -> Int
Hashable, Int -> OrdinalData -> ShowS
[OrdinalData] -> ShowS
OrdinalData -> String
(Int -> OrdinalData -> ShowS)
-> (OrdinalData -> String)
-> ([OrdinalData] -> ShowS)
-> Show OrdinalData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OrdinalData] -> ShowS
$cshowList :: [OrdinalData] -> ShowS
show :: OrdinalData -> String
$cshow :: OrdinalData -> String
showsPrec :: Int -> OrdinalData -> ShowS
$cshowsPrec :: Int -> OrdinalData -> ShowS
Show, Eq OrdinalData
Eq OrdinalData
-> (OrdinalData -> OrdinalData -> Ordering)
-> (OrdinalData -> OrdinalData -> Bool)
-> (OrdinalData -> OrdinalData -> Bool)
-> (OrdinalData -> OrdinalData -> Bool)
-> (OrdinalData -> OrdinalData -> Bool)
-> (OrdinalData -> OrdinalData -> OrdinalData)
-> (OrdinalData -> OrdinalData -> OrdinalData)
-> Ord OrdinalData
OrdinalData -> OrdinalData -> Bool
OrdinalData -> OrdinalData -> Ordering
OrdinalData -> OrdinalData -> OrdinalData
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: OrdinalData -> OrdinalData -> OrdinalData
$cmin :: OrdinalData -> OrdinalData -> OrdinalData
max :: OrdinalData -> OrdinalData -> OrdinalData
$cmax :: OrdinalData -> OrdinalData -> OrdinalData
>= :: OrdinalData -> OrdinalData -> Bool
$c>= :: OrdinalData -> OrdinalData -> Bool
> :: OrdinalData -> OrdinalData -> Bool
$c> :: OrdinalData -> OrdinalData -> Bool
<= :: OrdinalData -> OrdinalData -> Bool
$c<= :: OrdinalData -> OrdinalData -> Bool
< :: OrdinalData -> OrdinalData -> Bool
$c< :: OrdinalData -> OrdinalData -> Bool
compare :: OrdinalData -> OrdinalData -> Ordering
$ccompare :: OrdinalData -> OrdinalData -> Ordering
$cp1Ord :: Eq OrdinalData
Ord, OrdinalData -> ()
(OrdinalData -> ()) -> NFData OrdinalData
forall a. (a -> ()) -> NFData a
rnf :: OrdinalData -> ()
$crnf :: OrdinalData -> ()
NFData)
instance Resolve OrdinalData where
type ResolvedValue OrdinalData = OrdinalData
resolve :: Context
-> Options
-> OrdinalData
-> Maybe (ResolvedValue OrdinalData, Bool)
resolve Context
_ Options
_ OrdinalData
x = (OrdinalData, Bool) -> Maybe (OrdinalData, Bool)
forall a. a -> Maybe a
Just (OrdinalData
x, Bool
False)
instance ToJSON OrdinalData where
toJSON :: OrdinalData -> Value
toJSON (OrdinalData Int
value) = [Pair] -> Value
object
[ Text
"type" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= (Text
"value" :: Text)
, Text
"value" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= Int
value
]
isBetween :: Ord a => a -> a -> a -> Bool
isBetween :: a -> a -> a -> Bool
isBetween a
x a
low a
high = a
low a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
x Bool -> Bool -> Bool
&& a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
high