Ver código fonte

Change definition of QueryRunner

jherve 1 ano atrás
pai
commit
559507d585
2 arquivos alterados com 11 adições e 15 exclusões
  1. 7 13
      src/LinkedIn/ArtDecoCardAlt.purs
  2. 4 2
      src/LinkedIn/Types.purs

+ 7 - 13
src/LinkedIn/ArtDecoCardAlt.purs

@@ -3,22 +3,16 @@ module LinkedIn.ArtDecoCardAlt where
 import Control.Monad.Except.Trans
 import Prelude
 
-import Control.Monad.Writer (Writer, tell)
-import Data.Either (Either(..), hush, note)
+import Data.Either (Either(..), note)
 import Data.Foldable (class Foldable, foldMap, foldlDefault, foldrDefault)
 import Data.Generic.Rep (class Generic)
-import Data.List (List)
 import Data.List.Types (NonEmptyList)
 import Data.Maybe (Maybe(..))
 import Data.Show.Generic (genericShow)
 import Data.Traversable (class Traversable, sequence, traverseDefault)
 import Effect (Effect)
-import Effect.Class.Console (log, logShow)
-import LinkedIn (DetachedNode)
-import LinkedIn.ArtDeco (ArtDecoPvsEntity, parseArtDecoPvsEntity)
-import LinkedIn.ArtDeco as AD
-import LinkedIn.Types (Parser, QueryError(..), QueryRunner)
-import LinkedIn.Utils (queryAll, queryOne, queryOneAndParse)
+import LinkedIn.Types (QueryError(..), QueryRunner)
+import LinkedIn.Utils (queryAll, queryOne)
 import Web.DOM (Node)
 import Web.DOM.Node (nodeName)
 
@@ -75,7 +69,7 @@ instance Traversable ArtDecoCardAltElement where
 
   traverse = \x -> traverseDefault x
 
-queryArtDecoCenterHeaderAlt ∷ Node → ExceptT QueryError Effect (ArtDecoCenterHeaderAlt Node)
+queryArtDecoCenterHeaderAlt ∷ QueryRunner (ArtDecoCenterHeaderAlt Node)
 queryArtDecoCenterHeaderAlt n = do
   bold <- runOne ":scope div.t-bold > span[aria-hidden=true]" n
   normal <-
@@ -84,7 +78,7 @@ queryArtDecoCenterHeaderAlt n = do
 
   pure $ ArtDecoCenterHeaderAlt {bold, normal: normal}
 
-queryArtDecoCardAlt ∷ Node → ExceptT QueryError Effect (ArtDecoCardAltElement Node)
+queryArtDecoCardAlt ∷ QueryRunner (ArtDecoCardAltElement Node)
 queryArtDecoCardAlt n = do
   pvs <- runOne ":scope div.pvs-entity--padded" n
   header <- queryArtDecoCenterHeaderAlt pvs
@@ -102,12 +96,12 @@ ignoreNotFound = mapExceptT (map ignoreNotFound')
       (Left q) -> Left q
       (Right n') -> Right (Just n')
 
-runOne ∷ String → Node → ExceptT QueryError Effect Node
+runOne ∷ String → QueryRunner Node
 runOne selector node = ExceptT $ do
   maybeNode <- queryOne selector node
   pure $ note (QNodeNotFoundError selector) maybeNode
 
-runAll ∷ String → Node → ExceptT QueryError Effect (NonEmptyList Node)
+runAll ∷ String → QueryRunner (NonEmptyList Node)
 runAll selector node = ExceptT $ do
   maybeNodes <- queryAll selector node
   pure $ note (QNodeListNotFoundError selector) maybeNodes

+ 4 - 2
src/LinkedIn/Types.purs

@@ -1,10 +1,12 @@
 module LinkedIn.Types where
 
 import Prelude
+
+import Control.Monad.Except (ExceptT)
 import Data.Either (Either)
-import Effect (Effect)
 import Data.Generic.Rep (class Generic)
 import Data.Show.Generic (genericShow)
+import Effect (Effect)
 import Web.DOM (Node)
 
 
@@ -30,4 +32,4 @@ derive instance Eq QueryError
 instance Show QueryError where
   show = genericShow
 
-type QueryRunner a = Node → Effect (Either QueryError a)
+type QueryRunner a = Node → ExceptT QueryError Effect a