Skip to content

Commit

Permalink
Add documentation to Array.clone and Array.pinnedClone
Browse files Browse the repository at this point in the history
  • Loading branch information
adithyaov committed Jan 2, 2024
1 parent 9508d41 commit 6a78aba
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions core/src/Streamly/Internal/Data/Array/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,19 @@ fromStreamD str = unsafeFreeze <$> MA.fromStreamD str
-- Cloning
-------------------------------------------------------------------------------

-- | @clone@ creates new immutable array from a given slice. The size of the
-- underlying raw array will be equal to the size of the given slice.
--
-- >>> import Streamly.Internal.Data.MutByteArray as MBA
-- >>> import Streamly.Internal.Data.Array as Array
-- >>> array = Array.fromList ['a', 'b', 'c', 'd', 'e', 'f']
-- >>> slice1 = Array.getSliceUnsafe 1 4 array
-- >>> slice2 = Array.clone slice1
-- >>> sizeOfMutableByteArray (Array.arrContents slice1)
-- 6
-- >>> sizeOfMutableByteArray (Array.arrContents slice2)
-- 4
--
{-# INLINE clone #-}
clone ::
( MonadIO m
Expand All @@ -334,6 +347,8 @@ clone ::
=> Array a -> m (Array a)
clone = fmap unsafeFreeze . MA.clone . unsafeThaw

-- | Similar to @clone@ but creates a pinned immutable array.
--
{-# INLINE pinnedClone #-}
pinnedClone ::
( MonadIO m
Expand Down

0 comments on commit 6a78aba

Please sign in to comment.