Selaa lähdekoodia

Remove non-exceptT functions

jherve 1 vuosi sitten
vanhempi
commit
6c15293880
2 muutettua tiedostoa jossa 13 lisäystä ja 31 poistoa
  1. 3 2
      src/LinkedIn.purs
  2. 10 29
      src/LinkedIn/Output.purs

+ 3 - 2
src/LinkedIn.purs

@@ -2,6 +2,7 @@ module LinkedIn (encodeToJson, getContext, extractFromDocument, extractFromDocum
 
 import Prelude
 
+import Control.Monad.Except (runExceptT)
 import Data.Argonaut.Core (Json)
 import Data.Argonaut.Encode (encodeJson)
 import Data.Either (Either(..))
@@ -30,10 +31,10 @@ extractFromDocument dom = do
 
   case ctx of
     Left l -> pure $ Left l
-    Right ctx' -> toOutput ctx' dom
+    Right ctx' -> runExceptT $ toOutput ctx' dom
 
 extractFromDocumentInContext :: PageUrl -> Document -> Effect (Either String Output)
-extractFromDocumentInContext = toOutput
+extractFromDocumentInContext url dom = runExceptT $ toOutput url dom
 
 encodeToJson :: Either String Output -> Json
 encodeToJson = encodeJson

+ 10 - 29
src/LinkedIn/Output.purs

@@ -2,7 +2,7 @@ module LinkedIn.Output (run, runToDetached, toOutput) where
 
 import Prelude
 
-import Control.Monad.Except (ExceptT, except, lift, runExceptT, withExceptT)
+import Control.Monad.Except (ExceptT, except, lift, withExceptT)
 import Data.Either (Either(..))
 import Data.Traversable (class Traversable, traverse)
 import Effect (Effect)
@@ -21,49 +21,30 @@ import Type.Proxy (Proxy(..))
 import Web.DOM (Document)
 
 run :: forall t.
-  Traversable t
-  => Extractible t
-  => Proxy t
-  -> Document
-  -> Effect (Either String Output)
-run prox dom = runExceptT $ run' prox dom
-
-run' :: forall t.
   Traversable t
   => Extractible t
   => Proxy t
   -> Document
   -> ExceptT String Effect Output
-run' prox dom = do
-  detached <- withExceptT (\_ -> "Error on detach") $ runToDetached' prox dom
+run prox dom = do
+  detached <- withExceptT (\_ -> "Error on detach") $ runToDetached prox dom
   asUI <- except $ fromDetachedToUI detached
   except $ LE.extract asUI
 
 runToDetached :: forall t.
-  Traversable t
-  => Extractible t
-  => Proxy t
-  -> Document
-  -> Effect (Either QueryError (t DetachedNode))
-runToDetached proxy dom = runExceptT $ runToDetached' proxy dom
-
-runToDetached' :: forall t.
   Traversable t
   => Extractible t
   => Proxy t
   -> Document
   -> ExceptT QueryError Effect (t DetachedNode)
-runToDetached' _ dom = do
+runToDetached _ dom = do
   qRes <- LE.query @t dom
   lift $ traverse toDetached qRes
 
-toOutput ∷ PageUrl → (Document → Effect (Either String Output))
-toOutput url dom = runExceptT $ toOutput' url dom
-
-toOutput' ∷ PageUrl → (Document → ExceptT String Effect Output)
-toOutput' = case _ of
-  UrlProjects _ -> run' (Proxy :: Proxy ProjectsPage)
-  UrlSkills _ -> run' (Proxy :: Proxy SkillsPage)
-  UrlWorkExperience _ -> run' (Proxy :: Proxy WorkExperiencesPage)
-  UrlJobOffer _ -> run' (Proxy :: Proxy JobOfferPage)
+toOutput ∷ PageUrl → (Document → ExceptT String Effect Output)
+toOutput = case _ of
+  UrlProjects _ -> run (Proxy :: Proxy ProjectsPage)
+  UrlSkills _ -> run (Proxy :: Proxy SkillsPage)
+  UrlWorkExperience _ -> run (Proxy :: Proxy WorkExperiencesPage)
+  UrlJobOffer _ -> run (Proxy :: Proxy JobOfferPage)
   _ -> const $ except $ Left "Not handled yet"