packages feed

foldl-exceptions 1.0.0.0 → 1.0.0.1

raw patch · 6 files changed

+104/−32 lines, 6 filesdep +foldl-exceptionsdep +hedgehogdep −doctestdep ~basedep ~safe-exceptionsPVP ok

version bump matches the API change (PVP)

Dependencies added: foldl-exceptions, hedgehog

Dependencies removed: doctest

Dependency ranges changed: base, safe-exceptions

API changes (from Hackage documentation)

Files

− changelog.md
@@ -1,3 +0,0 @@-1.0.0.0--  * Initial release
foldl-exceptions.cabal view
@@ -1,10 +1,10 @@-cabal-version: 2.0+cabal-version: 3.0  name: foldl-exceptions-version: 1.0.0.0+version: 1.0.0.1  synopsis: Exception handling with FoldM-category: Web+category: Control  description:     Adds support for tuning exception handling behavior when@@ -16,31 +16,32 @@ author:     Chris Martin maintainer: Chris Martin, Julie Moronuki -copyright: 2018 Typeclass Consulting, LLC+copyright: 2019 Mission Valley Software LLC license: MIT license-file: license.txt  build-type: Simple-tested-with: GHC==8.6.1 -extra-source-files:-    changelog.md+common base+    default-language: Haskell2010+    default-extensions: ScopedTypeVariables, TypeApplications+    ghc-options: -Wall+    build-depends:+        base ^>= 4.10 || ^>= 4.11 || ^>= 4.12 || ^>= 4.13 || ^>= 4.14 || ^>= 4.15 || ^>= 4.16+      , foldl ^>= 1.4+      , safe-exceptions ^>= 0.1.5  library+    import: base     hs-source-dirs: library-    default-language: Haskell2010--    exposed-modules:-        Control.Foldl.Exceptions--    build-depends:-        base >=4.10 && <5-      , foldl-      , safe-exceptions+    exposed-modules: Control.Foldl.Exceptions -test-suite doctest+test-suite test-foldl-exceptions+    import: base     type: exitcode-stdio-1.0-    hs-source-dirs: test+    hs-source-dirs: test-suite/test-foldl-exceptions     default-language: Haskell2010-    main-is: doctest.hs-    build-depends: base, doctest+    main-is: Main.hs+    build-depends:+        foldl-exceptions+      , hedgehog ^>= 0.6 || ^>= 1.0 || ^>= 1.1
library/Control/Foldl/Exceptions.hs view
@@ -1,8 +1,3 @@-{-# OPTIONS_GHC -Wall #-}--{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE TypeApplications    #-}- {- |  When 'IO' is the monad of a monadic fold, each step in the evaluation of the
license.txt view
@@ -1,4 +1,4 @@-Copyright 2019 Typeclass Consulting, LLC+Copyright 2019 Mission Valley Software LLC  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in
+ test-suite/test-foldl-exceptions/Main.hs view
@@ -0,0 +1,82 @@+{-# LANGUAGE TemplateHaskell #-}++module Main (main) where++import Control.Foldl.Exceptions++import Control.Exception+import Control.Monad+import Control.Monad.IO.Class+import Hedgehog+import System.Exit+import System.IO++import qualified Control.Foldl as L++main :: IO ()+main = do+    hSetEncoding stdout utf8+    hSetEncoding stderr utf8+    ok <- checkParallel $$discover+    when (not ok) exitFailure++prop_1 :: Property+prop_1 = withTests 1 $ property $ do+    let f x = if x < 10 then return x else throw Overflow+    let xs = [1, 2, 500, 4] :: [Integer]++    -- Since (f 500) produces an exception, the following fold fails:+    let fold1 = L.premapM f (L.generalize L.list)+    r1 :: Either ArithException [Integer] <- liftIO $ try $ L.foldM fold1 xs+    r1 === Left Overflow++    -- By applying 'untilFirstException', we can produce a new fold that returns+    -- the intermediate result at the point where the exception occurs.+    let fold2 = exHalt_ fold1+    r2 :: [Integer] <- liftIO $ L.foldM fold2 xs+    r2 === [1, 2]++prop_2 :: Property+prop_2 = withTests 1 $ property $ do+    let f x = if x < 10 then return x else throw Overflow+    let xs = [1, 2, 500, 4] :: [Integer]++    let fold1 = L.premapM f (L.generalize L.list)+    let fold2 = exHalt @ArithException fold1++    r :: (Maybe ArithException, [Integer]) <- liftIO $ L.foldM fold2 xs+    r === (Just Overflow, [1, 2])++prop_3 :: Property+prop_3 = withTests 1 $ property $ do+    let f x = if x < 10 then return x else throw Overflow+    let xs = [1, 2, 500, 4] :: [Integer]++    -- Since (f 500) produces an exception, the following fold fails:+    let fold1 = L.premapM f (L.generalize L.list)+    r1 :: Either ArithException [Integer] <- liftIO $ try $ L.foldM fold1 xs+    r1 === Left Overflow++    -- By applying 'exSkip_', we can produce a new fold that produces+    -- a result from all steps that /don't/ fail:++    let fold2 = exSkip_ fold1+    r2 :: [Integer] <- liftIO $ L.foldM fold2 xs+    r2 === [1, 2, 4]++prop_4 :: Property+prop_4 = withTests 1 $ property $ do+    let f x = if x < 10 then return x else throw Overflow+    let xs = [1, 2, 500, 4] :: [Integer]++    -- Since (f 500) produces an exception, the following fold fails:+    let fold1 = L.premapM f (L.generalize L.list)+    r1 :: Either ArithException [Integer] <- liftIO $ try $ L.foldM fold1 xs+    r1 === Left Overflow++    -- By applying 'exSkip', we can produce a new fold that produces+    -- a result from all steps that /don't/ fail:++    let fold2 = exSkip @ArithException fold1+    r2 :: ([ArithException], [Integer]) <- liftIO $ L.foldM fold2 xs+    r2 === ([Overflow], [1, 2, 4])
− test/doctest.hs
@@ -1,3 +0,0 @@-import Test.DocTest--main = doctest ["library/Control/Foldl/Exceptions.hs"]