module LensUtils
(
overStrict
, setStrict
, zonedTimeLocalTime
, localTimeTimeOfDay
) where
import Control.Lens
import Data.Time
import StrictUnit
overStrict :: LensLike ((,) StrictUnit) s t a b -> (a -> b) -> s -> t
overStrict l f = run . l (nur . f)
where
nur y = (y `seq` StrictUnit, y)
run (StrictUnit,y) = y
{-# INLINE overStrict #-}
setStrict :: ASetter s t a b -> b -> s -> t
setStrict l x = set l $! x
{-# INLINE setStrict #-}
zonedTimeLocalTime :: Lens' ZonedTime LocalTime
zonedTimeLocalTime f (ZonedTime t z) = f t <&> \t' -> ZonedTime t' z
{-# INLINE zonedTimeLocalTime #-}
localTimeTimeOfDay :: Lens' LocalTime TimeOfDay
localTimeTimeOfDay f (LocalTime d t) = LocalTime d <$> f t
{-# INLINE localTimeTimeOfDay #-}