Skip to content

Commit

Permalink
Implement requested changes from #146 review
Browse files Browse the repository at this point in the history
  • Loading branch information
Cole Miller committed Aug 21, 2020
1 parent 4ddbfed commit 2cd5ce9
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 13 deletions.
6 changes: 5 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[0.11.0.0]
* [Add `indexMaybe` and synonym `(!?)` for indexing that returns `Maybe`](https://github.com/haskell/bytestring/pull/261)

[0.11.0.0]: https://github.com/haskell/bytestring/compare/0.10.12.0...0.11.0.0

[0.10.12.0] – August 2020

* **Note:** There are several breaking changes planned to be included in v0.11.
Expand All @@ -9,7 +14,6 @@
* [Add `IsList` instances for strict and lazy `ByteString` and for `ShortByteString`](https://github.com/haskell/bytestring/pull/219)
* [Add `createUpToN'` and `unsafeCreateUpToN'` to `Data.ByteString.Internal`](https://github.com/haskell/bytestring/pull/245)
* [Add `boundedPrim` to `Data.ByteString.Builder.Prim.Internal` and deprecate `boudedPrim`](https://github.com/haskell/bytestring/pull/246)
* Add `indexMaybe` and synonym `(!?)` for indexing that returns `Maybe`
* [Deprecate the `Data.ByteString.Lazy.Builder` and `Data.ByteString.Lazy.Builder.{ASCII,Extras}` modules](https://github.com/haskell/bytestring/pull/250)
* [Fix documented complexity of `Data.ByteString.Lazy.length`](https://github.com/haskell/bytestring/pull/255)
* [Assorted documentation fixes](https://github.com/haskell/bytestring/pull/248)
Expand Down
4 changes: 2 additions & 2 deletions Data/ByteString.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ index ps n
--
-- > 0 <= n < length bs
--
-- @since 0.10.10.1
-- @since 0.11.0.0
indexMaybe :: ByteString -> Int -> Maybe Word8
indexMaybe ps n
| n < 0 = Nothing
Expand All @@ -1115,7 +1115,7 @@ indexMaybe ps n
--
-- > 0 <= n < length bs
--
-- @since 0.10.10.1
-- @since 0.11.0.0
(!?) :: ByteString -> Int -> Maybe Word8
(!?) = indexMaybe
{-# INLINE (!?) #-}
Expand Down
6 changes: 3 additions & 3 deletions Data/ByteString/Char8.hs
Original file line number Diff line number Diff line change
Expand Up @@ -650,16 +650,16 @@ index = (w2c .) . B.index
--
-- > 0 <= n < length bs
--
-- @since 0.10.10.1
-- @since 0.11.0.0
indexMaybe :: ByteString -> Int -> Maybe Char
indexMaybe = ((fmap w2c) .) . B.indexMaybe
indexMaybe = (fmap w2c .) . B.indexMaybe
{-# INLINE indexMaybe #-}

-- | /O(1)/ 'ByteString' index, starting from 0, that returns 'Just' if:
--
-- > 0 <= n < length bs
--
-- @since 0.10.10.1
-- @since 0.11.0.0
(!?) :: ByteString -> Int -> Maybe Char
(!?) = indexMaybe
{-# INLINE (!?) #-}
Expand Down
4 changes: 2 additions & 2 deletions Data/ByteString/Lazy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ index cs0 i = index' cs0 i
--
-- > 0 <= n < length bs
--
-- @since 0.10.10.1
-- @since 0.11.0.0
indexMaybe :: ByteString -> Int64 -> Maybe Word8
indexMaybe _ i | i < 0 = Nothing
indexMaybe cs0 i = index' cs0 i
Expand All @@ -915,7 +915,7 @@ indexMaybe cs0 i = index' cs0 i
--
-- > 0 <= n < length bs
--
-- @since 0.10.10.1
-- @since 0.11.0.0
(!?) :: ByteString -> Int64 -> Maybe Word8
(!?) = indexMaybe
{-# INLINE (!?) #-}
Expand Down
6 changes: 3 additions & 3 deletions Data/ByteString/Lazy/Char8.hs
Original file line number Diff line number Diff line change
Expand Up @@ -533,16 +533,16 @@ index = (w2c .) . L.index
--
-- > 0 <= n < length bs
--
-- @since 0.10.10.1
-- @since 0.11.0.0
indexMaybe :: ByteString -> Int64 -> Maybe Char
indexMaybe = ((fmap w2c) .) . L.indexMaybe
indexMaybe = (fmap w2c .) . L.indexMaybe
{-# INLINE indexMaybe #-}

-- | /O(1)/ 'ByteString' index, starting from 0, that returns 'Just' if:
--
-- > 0 <= n < length bs
--
-- @since 0.10.10.1
-- @since 0.11.0.0
(!?) :: ByteString -> Int64 -> Maybe Char
(!?) = indexMaybe
{-# INLINE (!?) #-}
Expand Down
4 changes: 2 additions & 2 deletions Data/ByteString/Short/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ index sbs i
--
-- > 0 <= n < length bs
--
-- @since 0.10.10.1
-- @since 0.11.0.0
indexMaybe :: ShortByteString -> Int -> Maybe Word8
indexMaybe sbs i
| i >= 0 && i < length sbs = Just $ unsafeIndex sbs i
Expand All @@ -230,7 +230,7 @@ indexMaybe sbs i
--
-- > 0 <= n < length bs
--
-- @since 0.10.10.1
-- @since 0.11.0.0
(!?) :: ShortByteString -> Int -> Maybe Word8
(!?) = indexMaybe

Expand Down

0 comments on commit 2cd5ce9

Please sign in to comment.