Skip to content

Commit e6660a7

Browse files
authored
Improve documentation for zip/unzip for unboxed vectors (#505)
1 parent 2ec25ab commit e6660a7

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

vector/src/Data/Vector/Unboxed.hs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,15 @@ module Data.Vector.Unboxed (
132132
-- ** Zipping
133133
zipWith, zipWith3, zipWith4, zipWith5, zipWith6,
134134
izipWith, izipWith3, izipWith4, izipWith5, izipWith6,
135+
-- *** Zipping tuples
136+
-- $zip
135137
zip, zip3, zip4, zip5, zip6,
136138

137139
-- ** Monadic zipping
138140
zipWithM, izipWithM, zipWithM_, izipWithM_,
139141

140142
-- ** Unzipping
143+
-- $unzip
141144
unzip, unzip3, unzip4, unzip5, unzip6,
142145

143146
-- * Working with predicates
@@ -970,6 +973,26 @@ iforM_ = G.iforM_
970973
-- Zipping
971974
-- -------
972975

976+
-- $zip
977+
--
978+
-- Following functions could be used to construct vector of tuples
979+
-- from tuple of vectors. This operation is done in /O(1)/ time and
980+
-- will share underlying buffers.
981+
--
982+
-- Note that variants from "Data.Vector.Generic" doesn't have this
983+
-- property.
984+
985+
-- $unzip
986+
--
987+
-- Following functions could be used to access underlying
988+
-- representation of array of tuples. They convert array to tuple of
989+
-- arrays. This operation is done in /O(1)/ time and will share
990+
-- underlying buffers.
991+
--
992+
-- Note that variants from "Data.Vector.Generic" doesn't have this
993+
-- property.
994+
995+
973996
-- | /O(min(m,n))/ Zip two vectors with the given function.
974997
zipWith :: (Unbox a, Unbox b, Unbox c)
975998
=> (a -> b -> c) -> Vector a -> Vector b -> Vector c

vector/src/Data/Vector/Unboxed/Mutable.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ module Data.Vector.Unboxed.Mutable (
4242
clear,
4343

4444
-- * Zipping and unzipping
45+
-- $zip
4546
zip, zip3, zip4, zip5, zip6,
4647
unzip, unzip3, unzip4, unzip5, unzip6,
4748

@@ -632,6 +633,13 @@ ifoldrM' :: (PrimMonad m, Unbox a) => (Int -> a -> b -> m b) -> b -> MVector (Pr
632633
ifoldrM' = G.ifoldrM'
633634

634635

636+
-- $zip
637+
--
638+
-- Following functions provide access to the representation of vector
639+
-- of tuples. Internally it's product of vectors for each element of
640+
-- tuple. Conversions are performed in /O(1)/ and produced vector will
641+
-- share underlying buffers with parameter vectors.
642+
635643
#define DEFINE_MUTABLE
636644
#include "unbox-tuple-instances"
637645

0 commit comments

Comments
 (0)