From 74b34987c932253e67eea1e278eae1a5034b0f1d Mon Sep 17 00:00:00 2001 From: Bodigrim Date: Wed, 18 Oct 2023 20:39:17 +0100 Subject: [PATCH] Add instance Foldable1 for Field, FieldLine, SectionArg and Name --- Cabal-syntax/src/Distribution/Fields/Field.hs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Cabal-syntax/src/Distribution/Fields/Field.hs b/Cabal-syntax/src/Distribution/Fields/Field.hs index 7f5b85809aa..c119ca5f1c0 100644 --- a/Cabal-syntax/src/Distribution/Fields/Field.hs +++ b/Cabal-syntax/src/Distribution/Fields/Field.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE DeriveFoldable #-} {-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE DeriveTraversable #-} @@ -36,6 +37,9 @@ import Distribution.Compat.Prelude import Distribution.Pretty (showTokenStr) import Distribution.Utils.Generic (fromUTF8BS) import Prelude () +#if MIN_VERSION_base(4,18,0) +import qualified Data.Foldable1 as F1 +#endif ------------------------------------------------------------------------------- -- Cabal file @@ -141,3 +145,30 @@ fieldLinesToString = intercalate "\n" . map toStr where toStr (FieldLine _ bs) = fromUTF8BS bs + +------------------------------------------------------------------------------- +-- Foldable1 +------------------------------------------------------------------------------- + +#if MIN_VERSION_base(4,18,0) + +-- | @since 3.12.0.0 +instance F1.Foldable1 Field where + foldMap1 f (Field x ys) = + F1.fold1 (F1.foldMap1 f x :| map (F1.foldMap1 f) ys) + foldMap1 f (Section x ys zs) = + F1.fold1 (F1.foldMap1 f x :| map (F1.foldMap1 f) ys ++ map (F1.foldMap1 f) zs) + +-- | @since 3.12.0.0 +instance F1.Foldable1 FieldLine where + foldMap1 = (. fieldLineAnn) + +-- | @since 3.12.0.0 +instance F1.Foldable1 SectionArg where + foldMap1 = (. sectionArgAnn) + +-- | @since 3.12.0.0 +instance F1.Foldable1 Name where + foldMap1 = (. nameAnn) + +#endif