{-|Module : GHCup.Types.JSON.UtilsDescription : Utils for TH splicesCopyright : (c) Julian Ospald, 2020License : LGPL-3.0Maintainer : hasufell@hasufell.deStability : experimentalPortability : portable-}module GHCup.Types.JSON.Utils whereimport Control.Applicative ( optional )import Data.Aeson ( FromJSON, Key, Object, (.:) )import Data.Aeson.Types ( Parser )import Data.Foldable ( asum )import Data.Functor ( (<&>) )import qualified Data.Text as TremoveLensFieldLabel :: String -> StringremoveLensFieldLabel str' = maybe str' T.unpack . T.stripPrefix (T.pack "_") . T.pack $ str'(.::?) :: FromJSON a => Object -> [Key] -> Parser (Maybe a)-- asum <$> traverse (o .:?) keys(.::?) o keys = optional $ asum (keys <&> (o .:))(.::) :: FromJSON a => Object -> [Key] -> Parser a(.::) o keys = asum $ keys <&> (o .:)