module LensUtils
(
overStrict
, setStrict
, zonedTimeLocalTime
, localTimeTimeOfDay
, localTimeDay
) 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) = (ZonedTime ?? z) <$> f t
{-# INLINE zonedTimeLocalTime #-}
localTimeTimeOfDay :: Lens' LocalTime TimeOfDay
localTimeTimeOfDay f (LocalTime d t) = LocalTime d <$> f t
{-# INLINE localTimeTimeOfDay #-}
localTimeDay :: Lens' LocalTime Day
localTimeDay f (LocalTime d t) = (LocalTime ?? t) <$> f d
{-# INLINE localTimeDay #-}