Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds recipe CapabilityPatternWithCheckedExceptions #262

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use the results from getPureScript
  • Loading branch information
afcondon committed Jan 5, 2021
commit cdbfa7161a3548105851478c07e48d7a4b3f6f8a
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ import App.Application (program)
import App.ProductionExcV as AppExcV
import Effect (Effect)
import Effect.Aff (launchAff_)
import Effect.Class (liftEffect)
import Effect.Class.Console (log)

-- | See CapabilityPatternNode for other, simpler, examples of this pattern

-- | Layer 0 - Running the `program` in this context
main :: Effect Unit
main = launchAff_ do
result <- AppExcV.runApp program { url: "http://www.purescript.org"}
liftEffect $ log "we got a result"
pure unit
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ instance getUserNameAppExcV :: GetUserName (AppExcV var) where
getUserName = do
env <- ask

foo <- safe $ (getPureScript env.url) # handleError (errorHandlersWithDefault unit)
name <- safe $ (getPureScript env.url) # handleError (errorHandlersWithDefault "there was an error!")

pure $ Name "AppExcV"
pure $ Name name

-- | an example of a function which combines the underlying services and thus
-- | has the possibility of raising errors from either one
Expand All @@ -92,15 +92,16 @@ getPureScript :: forall m r
. Monad m
=> MonadHttp m
=> MonadFs m
=> String -> ExceptV (HttpError + FsError + r) m Unit
=> String -> ExceptV (HttpError + FsError + r) m String
getPureScript url = do
HTTP.get url >>= FS.write "~/purescript.html"
pure "some result"


-- | this function is used to declutter the implementation of `getUserName`
-- | Provides exception handling functions for the _combined_ exceptions of HTTP and FS services
-- | such that the `ExceptV` can be entirely unwrapped, using `safe` from `checked-exceptions`
errorHandlersWithDefault :: forall m r a.
errorHandlersWithDefault :: forall m a.
MonadEffect m =>
a ->
{ fsFileNotFound :: FilePath -> m a
Expand Down