module Duckling.Duration.Helpers
( duration
, isGrain
, isNatural
, isNumeralWith
) where
import Prelude
import Duckling.Dimensions.Types
import Duckling.Duration.Types (DurationData (DurationData))
import qualified Duckling.Duration.Types as TDuration
import Duckling.Numeral.Types (NumeralData (NumeralData))
import qualified Duckling.Numeral.Types as TNumeral
import qualified Duckling.TimeGrain.Types as TG
import Duckling.Types
isGrain :: TG.Grain -> Predicate
isGrain value (Token TimeGrain grain) = grain == value
isGrain _ _ = False
isNatural :: Predicate
isNatural (Token Numeral NumeralData {TNumeral.value = x}) =
TNumeral.isNatural x
isNatural _ = False
isNumeralWith :: (NumeralData -> t) -> (t -> Bool) -> PatternItem
isNumeralWith f pred = Predicate $ \x -> case x of
(Token Numeral x) -> pred $ f x
_ -> False
duration :: TG.Grain -> Int -> DurationData
duration grain n = DurationData {TDuration.grain = grain, TDuration.value = n}