strict-list 0.1.3 → 0.1.4
raw patch · 3 files changed
+18/−1 lines, 3 files
Files
- library/StrictList.hs +14/−0
- strict-list.cabal +1/−1
- test/Main.hs +3/−0
library/StrictList.hs view
@@ -243,6 +243,20 @@ in loop Nil Nil {-|+Same as @(`span` predicate . `reverse`)@.+-}+spanFromEnding :: (a -> Bool) -> List a -> (List a, List a)+spanFromEnding predicate = let+ loop !confirmedPrefix !unconfirmedPrefix !suffix = \ case+ Cons head tail -> if predicate head+ then loop confirmedPrefix (Cons head unconfirmedPrefix) (Cons head suffix) tail+ else let+ !prefix = Cons head unconfirmedPrefix+ in loop prefix prefix Nil tail+ Nil -> (suffix, confirmedPrefix)+ in loop Nil Nil Nil++{-| Get the first element and the remainder of the list if it's not empty. -} uncons :: List a -> Maybe (a, List a)
strict-list.cabal view
@@ -1,5 +1,5 @@ name: strict-list-version: 0.1.3+version: 0.1.4 synopsis: Strict linked list description: Implementation of strict linked list with care taken about stack.
test/Main.hs view
@@ -59,6 +59,9 @@ testProperty "dropWhileFromEnding" $ forAll ((,) <$> predicateGen <*> strictAndLazyListGen) $ \ (predicate, (strict, lazy)) -> toList (dropWhileFromEnding predicate strict) === Lazy.dropWhile predicate (Lazy.reverse lazy) ,+ testProperty "spanFromEnding" $ forAll ((,) <$> predicateGen <*> strictAndLazyListGen) $ \ (predicate, (strict, lazy)) ->+ bimap toList toList (spanFromEnding predicate strict) === Lazy.span predicate (Lazy.reverse lazy)+ , testProperty "head" $ forAll strictAndLazyListGen $ \ (strict, lazy) -> head strict === listToMaybe lazy ,