acc 0.1.0.2 → 0.1.1
raw patch · 4 files changed
+37/−1 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Acc: toNonEmpty :: Acc a -> Maybe (NonEmpty a)
Files
- acc.cabal +1/−1
- library/Acc.hs +12/−0
- library/Acc/BinTree1.hs +18/−0
- test/Main.hs +6/−0
acc.cabal view
@@ -1,5 +1,5 @@ name: acc-version: 0.1.0.2+version: 0.1.1 synopsis: Sequence optimized for monoidal construction and folding description: Data structure intended for accumulating a sequence of elements
library/Acc.hs view
@@ -6,6 +6,7 @@ snoc, uncons, unsnoc,+ toNonEmpty, ) where @@ -212,5 +213,16 @@ Just (res, TreeAcc newTree) BinTree1.Leaf res -> Just (res, EmptyAcc)+ EmptyAcc ->+ Nothing++{-|+Convert to non empty list if it's not empty.+-}+toNonEmpty :: Acc a -> Maybe (NonEmpty a)+toNonEmpty =+ \ case+ TreeAcc tree ->+ Just (BinTree1.toNonEmpty tree) EmptyAcc -> Nothing
library/Acc/BinTree1.hs view
@@ -15,6 +15,7 @@ unconsTo, unsnoc, unsnocTo,+ toNonEmpty, ) where @@ -205,3 +206,20 @@ unsnocTo (Branch l buff) r Leaf a -> (a, buff)++toNonEmpty :: BinTree1 a -> NonEmpty a+toNonEmpty =+ findFirst+ where+ findFirst =+ \ case+ Branch l r ->+ findFirstOnBranch l r+ Leaf a ->+ a :| []+ findFirstOnBranch l r =+ case l of+ Branch ll lr ->+ findFirstOnBranch ll (Branch lr r)+ Leaf a ->+ a :| foldr (:) [] r
test/Main.hs view
@@ -9,6 +9,7 @@ import Test.Tasty.QuickCheck import Acc import qualified Test.QuickCheck as QuickCheck+import qualified Data.List.NonEmpty as NonEmpty main =@@ -54,6 +55,11 @@ \ (acc :: Acc Int) -> foldMap' (: []) acc === foldMap' (: []) (toList acc)+ ,+ testProperty "toNonEmpty" $+ \ (acc :: Acc Int) ->+ Acc.toNonEmpty acc ===+ NonEmpty.nonEmpty (toList acc) ] instance Arbitrary a => Arbitrary (Acc a) where