瀏覽代碼

Add Foldable instances

jherve 1 年之前
父節點
當前提交
9881a35876
共有 3 個文件被更改,包括 46 次插入1 次删除
  1. 31 0
      src/LinkedIn/ArtDeco.purs
  2. 8 1
      src/LinkedIn/ArtDecoCard.purs
  3. 7 0
      src/LinkedIn/ArtDecoTab.purs

+ 31 - 0
src/LinkedIn/ArtDeco.purs

@@ -3,6 +3,7 @@ module LinkedIn.ArtDeco where
 import Prelude
 
 import Data.Either (Either(..), hush)
+import Data.Foldable (class Foldable, foldMap, foldlDefault, foldrDefault)
 import Data.Generic.Rep (class Generic)
 import Data.List (List)
 import Data.List.NonEmpty (NonEmptyList)
@@ -44,30 +45,60 @@ instance Show a => Show (ArtDecoPvsEntitySubComponent a) where
   show = genericShow
 derive instance Functor ArtDecoPvsEntitySubComponent
 
+instance Foldable ArtDecoPvsEntitySubComponent where
+  foldMap f (ArtDecoPvsEntitySubComponent sc) = foldMap f sc
+
+  foldl = \x -> foldlDefault x
+  foldr = \x -> foldrDefault x
+
 derive instance Generic (ArtDecoCenterContent a) _
 derive instance Eq a => Eq(ArtDecoCenterContent a)
 instance Show a => Show(ArtDecoCenterContent a) where
   show = genericShow
 derive instance Functor ArtDecoCenterContent
 
+instance Foldable ArtDecoCenterContent where
+  foldMap f (ArtDecoCenterContent c) = foldMap (foldMap f) c
+
+  foldl = \x -> foldlDefault x
+  foldr = \x -> foldrDefault x
+
 derive instance Generic (ArtDecoCenterHeader a) _
 derive instance Eq a => Eq(ArtDecoCenterHeader a)
 instance Show a => Show(ArtDecoCenterHeader a) where
   show = genericShow
 derive instance Functor ArtDecoCenterHeader
 
+instance Foldable ArtDecoCenterHeader where
+  foldMap f (ArtDecoCenterHeader {bold, normal, light}) = f bold <> foldMap f normal <> foldMap (foldMap f) light
+
+  foldl = \x -> foldlDefault x
+  foldr = \x -> foldrDefault x
+
 derive instance Generic (ArtDecoCenter a) _
 derive instance Eq a => Eq(ArtDecoCenter a)
 instance Show a => Show(ArtDecoCenter a) where
   show = genericShow
 derive instance Functor ArtDecoCenter 
 
+instance Foldable ArtDecoCenter where
+  foldMap f (ArtDecoCenter {header, content}) = foldMap f header <> foldMap f content
+
+  foldl = \x -> foldlDefault x
+  foldr = \x -> foldrDefault x
+
 derive instance Generic (ArtDecoPvsEntity a) _
 derive instance Eq a => Eq(ArtDecoPvsEntity a)
 instance Show a => Show(ArtDecoPvsEntity a) where
   show = genericShow
 derive instance Functor ArtDecoPvsEntity
 
+instance Foldable ArtDecoPvsEntity where
+  foldMap f (ArtDecoPvsEntity {side: _, center}) = foldMap f center
+
+  foldl = \x -> foldlDefault x
+  foldr = \x -> foldrDefault x
+
 parseArtDecoPvsEntitySubComponent ∷ Parser (ArtDecoPvsEntitySubComponent DetachedNode)
 parseArtDecoPvsEntitySubComponent n = do
   content <- queryAndDetachOne "span[aria-hidden=true]" n

+ 8 - 1
src/LinkedIn/ArtDecoCard.purs

@@ -2,6 +2,7 @@ module LinkedIn.ArtDecoCard where
 
 import Prelude
 
+import Data.Foldable (class Foldable, foldMap, foldlDefault, foldrDefault)
 import Data.Generic.Rep (class Generic)
 import Data.List (List)
 import Data.List.Types (NonEmptyList)
@@ -10,9 +11,9 @@ import Data.Show.Generic (genericShow)
 import LinkedIn (DetachedNode)
 import LinkedIn.ArtDeco (ArtDecoPvsEntity, parseArtDecoPvsEntity)
 import LinkedIn.ArtDeco as AD
+import LinkedIn.QueryRunner (QueryRunner, ignoreNotFound, queryAll, queryOne)
 import LinkedIn.Types (Parser)
 import LinkedIn.Utils (queryOneAndParse)
-import LinkedIn.QueryRunner (QueryRunner, ignoreNotFound, queryAll, queryOne)
 
 
 data ArtDecoCardElement a = ArtDecoCardElement {
@@ -25,6 +26,12 @@ instance Show a => Show (ArtDecoCardElement a) where
   show = genericShow
 derive instance Functor ArtDecoCardElement
 
+instance Foldable ArtDecoCardElement where
+  foldMap f (ArtDecoCardElement {pvs_entity}) = foldMap f pvs_entity
+
+  foldl = \x -> foldlDefault x
+  foldr = \x -> foldrDefault x
+
 parseArtDecoCard :: Parser (ArtDecoCardElement DetachedNode)
 parseArtDecoCard n = do
   pvs <- queryOneAndParse ":scope div.pvs-entity--padded" parseArtDecoPvsEntity n

+ 7 - 0
src/LinkedIn/ArtDecoTab.purs

@@ -2,6 +2,7 @@ module LinkedIn.ArtDecoTab where
 
 import Prelude
 
+import Data.Foldable (class Foldable, foldMap, foldlDefault, foldrDefault)
 import Data.Generic.Rep (class Generic)
 import Data.List (List)
 import Data.List.Types (NonEmptyList)
@@ -24,6 +25,12 @@ instance Show a => Show (ArtDecoTabElement a) where
   show = genericShow
 derive instance Functor ArtDecoTabElement
 
+instance Foldable ArtDecoTabElement where
+  foldMap f (ArtDecoTabElement {pvs_entity}) = foldMap f pvs_entity
+
+  foldl = \x -> foldlDefault x
+  foldr = \x -> foldrDefault x
+
 parseArtDecoTab :: Parser (ArtDecoTabElement DetachedNode)
 parseArtDecoTab n = do
   pvs <- queryOneAndParse ":scope div.pvs-entity--padded" parseArtDecoPvsEntity n