Procházet zdrojové kódy

Finally get a result with ExceptT

jherve před 1 rokem
rodič
revize
0bbc6bef15
1 změnil soubory, kde provedl 9 přidání a 18 odebrání
  1. 9 18
      src/LinkedIn/ArtDecoCardAlt.purs

+ 9 - 18
src/LinkedIn/ArtDecoCardAlt.purs

@@ -1,14 +1,17 @@
 module LinkedIn.ArtDecoCardAlt where
 module LinkedIn.ArtDecoCardAlt where
 
 
+import Control.Monad.Except.Trans
 import Prelude
 import Prelude
 
 
-import Data.Either (Either(..), note)
+import Control.Monad.Writer (Writer, tell)
+import Data.Either (Either(..), hush, note)
 import Data.Generic.Rep (class Generic)
 import Data.Generic.Rep (class Generic)
 import Data.List (List)
 import Data.List (List)
 import Data.List.Types (NonEmptyList)
 import Data.List.Types (NonEmptyList)
 import Data.Maybe (Maybe)
 import Data.Maybe (Maybe)
 import Data.Show.Generic (genericShow)
 import Data.Show.Generic (genericShow)
 import Effect (Effect)
 import Effect (Effect)
+import Effect.Class.Console (log, logShow)
 import LinkedIn (DetachedNode)
 import LinkedIn (DetachedNode)
 import LinkedIn.ArtDeco (ArtDecoPvsEntity, parseArtDecoPvsEntity)
 import LinkedIn.ArtDeco (ArtDecoPvsEntity, parseArtDecoPvsEntity)
 import LinkedIn.ArtDeco as AD
 import LinkedIn.ArtDeco as AD
@@ -46,25 +49,13 @@ instance Functor ArtDecoCardAltElement where
   map f (ArtDecoCardAltElement {pvs_entity}) =
   map f (ArtDecoCardAltElement {pvs_entity}) =
     ArtDecoCardAltElement ({pvs_entity: map f pvs_entity})
     ArtDecoCardAltElement ({pvs_entity: map f pvs_entity})
 
 
-queryArtDecoCenterHeaderAlt :: Node → Effect (Either QueryError (ArtDecoCenterHeaderAlt Node))
-queryArtDecoCenterHeaderAlt n = do
-  bold <- runOne ":scope div.t-bold > span[aria-hidden=true]" n
-
-  pure $ ado
-    b <- bold
-  in ArtDecoCenterHeaderAlt {bold: b}
-
 queryArtDecoCardAlt :: Node → Effect (Either QueryError (ArtDecoCardAltElement Node))
 queryArtDecoCardAlt :: Node → Effect (Either QueryError (ArtDecoCardAltElement Node))
 queryArtDecoCardAlt n = do
 queryArtDecoCardAlt n = do
-  pvs <- runOne ":scope div.pvs-entity--padded" n
-
-  case pvs of
-    Left l -> pure $ Left l
-    Right p -> do
-      header <- queryArtDecoCenterHeaderAlt p
-      pure $ ado
-        h <- header
-      in ArtDecoCardAltElement {pvs_entity: h}
+  eitherResult <- runExceptT do
+    pvs <- ExceptT $ runOne ":scope div.pvs-entity--padded" n
+    bold <- ExceptT $ runOne ":scope div.t-bold > span[aria-hidden=true]" pvs
+    pure $ ArtDecoCardAltElement { pvs_entity: ArtDecoCenterHeaderAlt {bold} }
+  pure eitherResult
 
 
 runOne ∷ String → Node → Effect (Either QueryError Node)
 runOne ∷ String → Node → Effect (Either QueryError Node)
 runOne selector node = do
 runOne selector node = do