packages feed

ilist 0.2.0.0 → 0.3.0.0

raw patch · 4 files changed

+16/−5 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Data.List.Index: ifind :: (Int -> a -> Bool) -> [a] -> Maybe a
+ Data.List.Index: ifind :: (Int -> a -> Bool) -> [a] -> Maybe (Int, a)
- Data.List.Index: ifoldl :: (b -> Int -> a -> b) -> b -> [a] -> b
+ Data.List.Index: ifoldl :: forall a b. (b -> Int -> a -> b) -> b -> [a] -> b
- Data.List.Index: ifoldl' :: (b -> Int -> a -> b) -> b -> [a] -> b
+ Data.List.Index: ifoldl' :: forall a b. (b -> Int -> a -> b) -> b -> [a] -> b

Files

CHANGELOG.md view
@@ -1,3 +1,7 @@+# 0.3.0.0++* `ifind` now returns the index alongside with the value (same as in `lens`).+ # 0.2.0.0  * `izipWithM` and `izipWithM_` have been generalised from `Monad` to `Applicative` (which mimics what was done in base-4.9).
ilist.cabal view
@@ -1,5 +1,5 @@ name:                ilist-version:             0.2.0.0+version:             0.3.0.0 synopsis:            Optimised list functions for doing index-related things description:   Optimised list functions for doing index-related things. They're faster than common idioms in all cases, and sometimes they fuse better as well.
lib/Data/List/Index.hs view
@@ -493,8 +493,13 @@ iselect p i x ~(ts,fs) | p i x     = (x:ts,fs)                        | otherwise = (ts, x:fs) -ifind :: (Int -> a -> Bool) -> [a] -> Maybe a-ifind p = listToMaybe . ifilter p+ifind :: (Int -> a -> Bool) -> [a] -> Maybe (Int, a)+ifind p ls = go 0# ls+  where+    go i (x:xs) | p (I# i) x = Just (I# i, x)+                | otherwise  = go (i +# 1#) xs+    go _ _ = Nothing+{-# INLINE ifind #-}  ifindIndex :: (Int -> a -> Bool) -> [a] -> Maybe Int ifindIndex p = listToMaybe . ifindIndices p
tests/Main.hs view
@@ -245,11 +245,13 @@ search = describe "search" $ do   describe "ifind" $ do     specify "found" $ do-      ifind (\i x -> i*2==x) [1,3,4,7] `shouldBe` Just 4+      ifind (\i x -> i*2==x) [1,3,4,7] `shouldBe` Just (2, 4)+    specify "found twice" $ do+      ifind (\i x -> i*2==x) [1,3,4,6] `shouldBe` Just (2, 4)     specify "not found" $ do       ifind (\i x -> i*2==x) [1,3,5,7] `shouldBe` Nothing     specify "empty" $ do-      ifind undefined [] `shouldBe` (Nothing :: Maybe Bool)+      ifind undefined [] `shouldBe` (Nothing :: Maybe (Int, Bool))    describe "ifindIndex" $ do     specify "found" $ do