packages feed

strict-list 0.1.0.1 → 0.1.1

raw patch · 3 files changed

+20/−2 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ StrictList: span :: (a -> Bool) -> List a -> (List a, List a)

Files

library/StrictList.hs view
@@ -170,6 +170,21 @@   Nil -> Nil  {-|+An optimized version of the same predicate applied to `takeWhile` and `dropWhile`.+IOW,++>span predicate list = (takeWhile predicate list, dropWhile predicate list)+-}+span :: (a -> Bool) -> List a -> (List a, List a)+span predicate = let+  buildPrefix !prefix = \ case+    Cons head tail -> if predicate head+      then buildPrefix (Cons head prefix) tail+      else (reverse prefix, Cons head tail)+    _ -> (reverse prefix, Nil)+  in buildPrefix Nil++{-| Same as @(`takeWhile` predicate . `reverse`)@. E.g.,  
strict-list.cabal view
@@ -1,5 +1,5 @@ name: strict-list-version: 0.1.0.1+version: 0.1.1 synopsis: Strict linked list description:   Implementation of strict linked list with care taken about stack.
test/Main.hs view
@@ -1,6 +1,6 @@ module Main where -import Prelude hiding (choose, reverse, toList, List, filter, take, drop, takeWhile, dropWhile, head, last, tail, init)+import Prelude hiding (span, choose, reverse, toList, List, filter, take, drop, takeWhile, dropWhile, head, last, tail, init) import GHC.Exts as Exports (IsList(..)) import Test.QuickCheck.Instances import Test.Tasty@@ -46,6 +46,9 @@     ,     testProperty "dropWhile" $ forAll ((,) <$> predicateGen <*> strictAndLazyListGen) $ \ (predicate, (strict, lazy)) ->     toList (dropWhile predicate strict) === Lazy.dropWhile predicate lazy+    ,+    testProperty "span" $ forAll ((,) <$> predicateGen <*> strictAndLazyListGen) $ \ (predicate, (strict, lazy)) ->+    bimap toList toList (span predicate strict) === Lazy.span predicate lazy     ,     testProperty "takeWhileFromEnding" $ forAll ((,) <$> predicateGen <*> strictAndLazyListGen) $ \ (predicate, (strict, lazy)) ->     toList (takeWhileFromEnding predicate strict) === Lazy.takeWhile predicate (Lazy.reverse lazy)