Add unsafeTake, unsafeDrop
[darcs-mirrors/vector.git] / Data / Vector.hs
1 {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, TypeFamilies #-}
2
3 -- |
4 -- Module : Data.Vector
5 -- Copyright : (c) Roman Leshchinskiy 2008-2009
6 -- License : BSD-style
7 --
8 -- Maintainer : Roman Leshchinskiy <rl@cse.unsw.edu.au>
9 -- Stability : experimental
10 -- Portability : non-portable
11 --
12 -- Boxed vectors
13 --
14
15 module Data.Vector (
16 Vector, MVector,
17
18 -- * Length information
19 length, null,
20
21 -- * Construction
22 empty, singleton, cons, snoc, replicate, generate, (++), copy,
23
24 -- * Accessing individual elements
25 (!), head, last, indexM, headM, lastM,
26 unsafeIndex, unsafeHead, unsafeLast,
27 unsafeIndexM, unsafeHeadM, unsafeLastM,
28
29 -- * Subvectors
30 slice, init, tail, take, drop,
31 unsafeSlice, unsafeInit, unsafeTail, unsafeTake, unsafeDrop,
32
33 -- * Permutations
34 accum, accumulate, accumulate_,
35 (//), update, update_,
36 backpermute, reverse,
37
38 -- * Mapping
39 map, imap, concatMap,
40
41 -- * Zipping and unzipping
42 zipWith, zipWith3, zipWith4, zipWith5, zipWith6,
43 izipWith, izipWith3, izipWith4, izipWith5, izipWith6,
44 zip, zip3, zip4, zip5, zip6,
45 unzip, unzip3, unzip4, unzip5, unzip6,
46
47 -- * Filtering
48 filter, ifilter, takeWhile, dropWhile,
49 unstablePartition, span, break,
50
51 -- * Searching
52 elem, notElem, find, findIndex, findIndices, elemIndex, elemIndices,
53
54 -- * Folding
55 foldl, foldl1, foldl', foldl1', foldr, foldr1,
56 ifoldl, ifoldl', ifoldr,
57
58 -- * Specialised folds
59 all, any, and, or,
60 sum, product,
61 maximum, maximumBy, minimum, minimumBy,
62 minIndex, minIndexBy, maxIndex, maxIndexBy,
63
64 -- * Unfolding
65 unfoldr,
66
67 -- * Scans
68 prescanl, prescanl',
69 postscanl, postscanl',
70 scanl, scanl', scanl1, scanl1',
71
72 -- * Enumeration
73 enumFromTo, enumFromThenTo,
74
75 -- * Conversion to/from lists
76 toList, fromList,
77
78 -- * Unsafe operations
79 unsafeAccum, unsafeAccumulate, unsafeAccumulate_,
80 unsafeUpd, unsafeUpdate, unsafeUpdate_
81 ) where
82
83 import qualified Data.Vector.Generic as G
84 import Data.Vector.Mutable ( MVector(..) )
85 import Data.Primitive.Array
86
87 import Control.Monad ( liftM )
88
89 import Prelude hiding ( length, null,
90 replicate, (++),
91 head, last,
92 init, tail, take, drop, reverse,
93 map, concatMap,
94 zipWith, zipWith3, zip, zip3, unzip, unzip3,
95 filter, takeWhile, dropWhile, span, break,
96 elem, notElem,
97 foldl, foldl1, foldr, foldr1,
98 all, any, and, or, sum, product, minimum, maximum,
99 scanl, scanl1,
100 enumFromTo, enumFromThenTo )
101
102 import qualified Prelude
103
104 data Vector a = Vector {-# UNPACK #-} !Int
105 {-# UNPACK #-} !Int
106 {-# UNPACK #-} !(Array a)
107
108 instance Show a => Show (Vector a) where
109 show = (Prelude.++ " :: Data.Vector.Vector") . ("fromList " Prelude.++) . show . toList
110
111 type instance G.Mutable Vector = MVector
112
113 instance G.Vector Vector a where
114 {-# INLINE unsafeFreeze #-}
115 unsafeFreeze (MVector i n marr)
116 = Vector i n `liftM` unsafeFreezeArray marr
117
118 {-# INLINE basicLength #-}
119 basicLength (Vector _ n _) = n
120
121 {-# INLINE basicUnsafeSlice #-}
122 basicUnsafeSlice j n (Vector i _ arr) = Vector (i+j) n arr
123
124 {-# INLINE basicUnsafeIndexM #-}
125 basicUnsafeIndexM (Vector i _ arr) j = indexArrayM arr (i+j)
126
127 instance Eq a => Eq (Vector a) where
128 {-# INLINE (==) #-}
129 (==) = G.eq
130
131 instance Ord a => Ord (Vector a) where
132 {-# INLINE compare #-}
133 compare = G.cmp
134
135 -- Length
136 -- ------
137
138 length :: Vector a -> Int
139 {-# INLINE length #-}
140 length = G.length
141
142 null :: Vector a -> Bool
143 {-# INLINE null #-}
144 null = G.null
145
146 -- Construction
147 -- ------------
148
149 -- | Empty vector
150 empty :: Vector a
151 {-# INLINE empty #-}
152 empty = G.empty
153
154 -- | Vector with exaclty one element
155 singleton :: a -> Vector a
156 {-# INLINE singleton #-}
157 singleton = G.singleton
158
159 -- | Vector of the given length with the given value in each position
160 replicate :: Int -> a -> Vector a
161 {-# INLINE replicate #-}
162 replicate = G.replicate
163
164 -- | Generate a vector of the given length by applying the function to each
165 -- index
166 generate :: Int -> (Int -> a) -> Vector a
167 {-# INLINE generate #-}
168 generate = G.generate
169
170 -- | Prepend an element
171 cons :: a -> Vector a -> Vector a
172 {-# INLINE cons #-}
173 cons = G.cons
174
175 -- | Append an element
176 snoc :: Vector a -> a -> Vector a
177 {-# INLINE snoc #-}
178 snoc = G.snoc
179
180 infixr 5 ++
181 -- | Concatenate two vectors
182 (++) :: Vector a -> Vector a -> Vector a
183 {-# INLINE (++) #-}
184 (++) = (G.++)
185
186 -- | Create a copy of a vector. Useful when dealing with slices.
187 copy :: Vector a -> Vector a
188 {-# INLINE copy #-}
189 copy = G.copy
190
191 -- Accessing individual elements
192 -- -----------------------------
193
194 -- | Indexing
195 (!) :: Vector a -> Int -> a
196 {-# INLINE (!) #-}
197 (!) = (G.!)
198
199 -- | First element
200 head :: Vector a -> a
201 {-# INLINE head #-}
202 head = G.head
203
204 -- | Last element
205 last :: Vector a -> a
206 {-# INLINE last #-}
207 last = G.last
208
209 -- | Unsafe indexing without bounds checking
210 unsafeIndex :: Vector a -> Int -> a
211 {-# INLINE unsafeIndex #-}
212 unsafeIndex = G.unsafeIndex
213
214 -- | Yield the first element of a vector without checking if the vector is
215 -- empty
216 unsafeHead :: Vector a -> a
217 {-# INLINE unsafeHead #-}
218 unsafeHead = G.unsafeHead
219
220 -- | Yield the last element of a vector without checking if the vector is
221 -- empty
222 unsafeLast :: Vector a -> a
223 {-# INLINE unsafeLast #-}
224 unsafeLast = G.unsafeLast
225
226 -- | Monadic indexing which can be strict in the vector while remaining lazy in
227 -- the element
228 indexM :: Monad m => Vector a -> Int -> m a
229 {-# INLINE indexM #-}
230 indexM = G.indexM
231
232 headM :: Monad m => Vector a -> m a
233 {-# INLINE headM #-}
234 headM = G.headM
235
236 lastM :: Monad m => Vector a -> m a
237 {-# INLINE lastM #-}
238 lastM = G.lastM
239
240 -- | Unsafe monadic indexing without bounds checks
241 unsafeIndexM :: Monad m => Vector a -> Int -> m a
242 {-# INLINE unsafeIndexM #-}
243 unsafeIndexM = G.unsafeIndexM
244
245 unsafeHeadM :: Monad m => Vector a -> m a
246 {-# INLINE unsafeHeadM #-}
247 unsafeHeadM = G.unsafeHeadM
248
249 unsafeLastM :: Monad m => Vector a -> m a
250 {-# INLINE unsafeLastM #-}
251 unsafeLastM = G.unsafeLastM
252
253 -- Subarrays
254 -- ---------
255
256 -- | Yield a part of the vector without copying it. Safer version of
257 -- 'basicUnsafeSlice'.
258 slice :: Int -- ^ starting index
259 -> Int -- ^ length
260 -> Vector a
261 -> Vector a
262 {-# INLINE slice #-}
263 slice = G.slice
264
265 -- | Yield all but the last element without copying.
266 init :: Vector a -> Vector a
267 {-# INLINE init #-}
268 init = G.init
269
270 -- | All but the first element (without copying).
271 tail :: Vector a -> Vector a
272 {-# INLINE tail #-}
273 tail = G.tail
274
275 -- | Yield the first @n@ elements without copying.
276 take :: Int -> Vector a -> Vector a
277 {-# INLINE take #-}
278 take = G.take
279
280 -- | Yield all but the first @n@ elements without copying.
281 drop :: Int -> Vector a -> Vector a
282 {-# INLINE drop #-}
283 drop = G.drop
284
285 -- | Unsafely yield a part of the vector without copying it and without
286 -- performing bounds checks.
287 unsafeSlice :: Int -- ^ starting index
288 -> Int -- ^ length
289 -> Vector a
290 -> Vector a
291 {-# INLINE unsafeSlice #-}
292 unsafeSlice = G.unsafeSlice
293
294 unsafeInit :: Vector a -> Vector a
295 {-# INLINE unsafeInit #-}
296 unsafeInit = G.unsafeInit
297
298 unsafeTail :: Vector a -> Vector a
299 {-# INLINE unsafeTail #-}
300 unsafeTail = G.unsafeTail
301
302 unsafeTake :: Int -> Vector a -> Vector a
303 {-# INLINE unsafeTake #-}
304 unsafeTake = G.unsafeTake
305
306 unsafeDrop :: Int -> Vector a -> Vector a
307 {-# INLINE unsafeDrop #-}
308 unsafeDrop = G.unsafeDrop
309
310 -- Permutations
311 -- ------------
312
313 unsafeAccum :: (a -> b -> a) -> Vector a -> [(Int,b)] -> Vector a
314 {-# INLINE unsafeAccum #-}
315 unsafeAccum = G.unsafeAccum
316
317 unsafeAccumulate :: (a -> b -> a) -> Vector a -> Vector (Int,b) -> Vector a
318 {-# INLINE unsafeAccumulate #-}
319 unsafeAccumulate = G.unsafeAccumulate
320
321 unsafeAccumulate_
322 :: (a -> b -> a) -> Vector a -> Vector Int -> Vector b -> Vector a
323 {-# INLINE unsafeAccumulate_ #-}
324 unsafeAccumulate_ = G.unsafeAccumulate_
325
326 accum :: (a -> b -> a) -> Vector a -> [(Int,b)] -> Vector a
327 {-# INLINE accum #-}
328 accum = G.accum
329
330 accumulate :: (a -> b -> a) -> Vector a -> Vector (Int,b) -> Vector a
331 {-# INLINE accumulate #-}
332 accumulate = G.accumulate
333
334 accumulate_ :: (a -> b -> a) -> Vector a -> Vector Int -> Vector b -> Vector a
335 {-# INLINE accumulate_ #-}
336 accumulate_ = G.accumulate_
337
338 unsafeUpd :: Vector a -> [(Int, a)] -> Vector a
339 {-# INLINE unsafeUpd #-}
340 unsafeUpd = G.unsafeUpd
341
342 unsafeUpdate :: Vector a -> Vector (Int, a) -> Vector a
343 {-# INLINE unsafeUpdate #-}
344 unsafeUpdate = G.unsafeUpdate
345
346 unsafeUpdate_ :: Vector a -> Vector Int -> Vector a -> Vector a
347 {-# INLINE unsafeUpdate_ #-}
348 unsafeUpdate_ = G.unsafeUpdate_
349
350 (//) :: Vector a -> [(Int, a)] -> Vector a
351 {-# INLINE (//) #-}
352 (//) = (G.//)
353
354 update :: Vector a -> Vector (Int, a) -> Vector a
355 {-# INLINE update #-}
356 update = G.update
357
358 update_ :: Vector a -> Vector Int -> Vector a -> Vector a
359 {-# INLINE update_ #-}
360 update_ = G.update_
361
362 backpermute :: Vector a -> Vector Int -> Vector a
363 {-# INLINE backpermute #-}
364 backpermute = G.backpermute
365
366 reverse :: Vector a -> Vector a
367 {-# INLINE reverse #-}
368 reverse = G.reverse
369
370 -- Mapping
371 -- -------
372
373 -- | Map a function over a vector
374 map :: (a -> b) -> Vector a -> Vector b
375 {-# INLINE map #-}
376 map = G.map
377
378 -- | Apply a function to every index/value pair
379 imap :: (Int -> a -> b) -> Vector a -> Vector b
380 {-# INLINE imap #-}
381 imap = G.imap
382
383 concatMap :: (a -> Vector b) -> Vector a -> Vector b
384 {-# INLINE concatMap #-}
385 concatMap = G.concatMap
386
387 -- Zipping/unzipping
388 -- -----------------
389
390 -- | Zip two vectors with the given function.
391 zipWith :: (a -> b -> c) -> Vector a -> Vector b -> Vector c
392 {-# INLINE zipWith #-}
393 zipWith = G.zipWith
394
395 -- | Zip three vectors with the given function.
396 zipWith3 :: (a -> b -> c -> d) -> Vector a -> Vector b -> Vector c -> Vector d
397 {-# INLINE zipWith3 #-}
398 zipWith3 = G.zipWith3
399
400 zipWith4 :: (a -> b -> c -> d -> e)
401 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
402 {-# INLINE zipWith4 #-}
403 zipWith4 = G.zipWith4
404
405 zipWith5 :: (a -> b -> c -> d -> e -> f)
406 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
407 -> Vector f
408 {-# INLINE zipWith5 #-}
409 zipWith5 = G.zipWith5
410
411 zipWith6 :: (a -> b -> c -> d -> e -> f -> g)
412 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
413 -> Vector f -> Vector g
414 {-# INLINE zipWith6 #-}
415 zipWith6 = G.zipWith6
416
417 -- | Zip two vectors and their indices with the given function.
418 izipWith :: (Int -> a -> b -> c) -> Vector a -> Vector b -> Vector c
419 {-# INLINE izipWith #-}
420 izipWith = G.izipWith
421
422 -- | Zip three vectors and their indices with the given function.
423 izipWith3 :: (Int -> a -> b -> c -> d)
424 -> Vector a -> Vector b -> Vector c -> Vector d
425 {-# INLINE izipWith3 #-}
426 izipWith3 = G.izipWith3
427
428 izipWith4 :: (Int -> a -> b -> c -> d -> e)
429 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
430 {-# INLINE izipWith4 #-}
431 izipWith4 = G.izipWith4
432
433 izipWith5 :: (Int -> a -> b -> c -> d -> e -> f)
434 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
435 -> Vector f
436 {-# INLINE izipWith5 #-}
437 izipWith5 = G.izipWith5
438
439 izipWith6 :: (Int -> a -> b -> c -> d -> e -> f -> g)
440 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
441 -> Vector f -> Vector g
442 {-# INLINE izipWith6 #-}
443 izipWith6 = G.izipWith6
444
445 zip :: Vector a -> Vector b -> Vector (a, b)
446 {-# INLINE zip #-}
447 zip = G.zip
448
449 zip3 :: Vector a -> Vector b -> Vector c -> Vector (a, b, c)
450 {-# INLINE zip3 #-}
451 zip3 = G.zip3
452
453 zip4 :: Vector a -> Vector b -> Vector c -> Vector d
454 -> Vector (a, b, c, d)
455 {-# INLINE zip4 #-}
456 zip4 = G.zip4
457
458 zip5 :: Vector a -> Vector b -> Vector c -> Vector d -> Vector e
459 -> Vector (a, b, c, d, e)
460 {-# INLINE zip5 #-}
461 zip5 = G.zip5
462
463 zip6 :: Vector a -> Vector b -> Vector c -> Vector d -> Vector e -> Vector f
464 -> Vector (a, b, c, d, e, f)
465 {-# INLINE zip6 #-}
466 zip6 = G.zip6
467
468 unzip :: Vector (a, b) -> (Vector a, Vector b)
469 {-# INLINE unzip #-}
470 unzip = G.unzip
471
472 unzip3 :: Vector (a, b, c) -> (Vector a, Vector b, Vector c)
473 {-# INLINE unzip3 #-}
474 unzip3 = G.unzip3
475
476 unzip4 :: Vector (a, b, c, d) -> (Vector a, Vector b, Vector c, Vector d)
477 {-# INLINE unzip4 #-}
478 unzip4 = G.unzip4
479
480 unzip5 :: Vector (a, b, c, d, e)
481 -> (Vector a, Vector b, Vector c, Vector d, Vector e)
482 {-# INLINE unzip5 #-}
483 unzip5 = G.unzip5
484
485 unzip6 :: Vector (a, b, c, d, e, f)
486 -> (Vector a, Vector b, Vector c, Vector d, Vector e, Vector f)
487 {-# INLINE unzip6 #-}
488 unzip6 = G.unzip6
489
490 -- Filtering
491 -- ---------
492
493 -- | Drop elements which do not satisfy the predicate
494 filter :: (a -> Bool) -> Vector a -> Vector a
495 {-# INLINE filter #-}
496 filter = G.filter
497
498 -- | Drop elements that do not satisfy the predicate (applied to values and
499 -- their indices)
500 ifilter :: (Int -> a -> Bool) -> Vector a -> Vector a
501 {-# INLINE ifilter #-}
502 ifilter = G.ifilter
503
504 -- | Yield the longest prefix of elements satisfying the predicate.
505 takeWhile :: (a -> Bool) -> Vector a -> Vector a
506 {-# INLINE takeWhile #-}
507 takeWhile = G.takeWhile
508
509 -- | Drop the longest prefix of elements that satisfy the predicate.
510 dropWhile :: (a -> Bool) -> Vector a -> Vector a
511 {-# INLINE dropWhile #-}
512 dropWhile = G.dropWhile
513
514 -- | Split the vector in two parts, the first one containing those elements
515 -- that satisfy the predicate and the second one those that don't. The order
516 -- of the elements is not preserved.
517 unstablePartition :: (a -> Bool) -> Vector a -> (Vector a, Vector a)
518 {-# INLINE unstablePartition #-}
519 unstablePartition = G.unstablePartition
520
521 -- | Split the vector into the longest prefix of elements that satisfy the
522 -- predicate and the rest.
523 span :: (a -> Bool) -> Vector a -> (Vector a, Vector a)
524 {-# INLINE span #-}
525 span = G.span
526
527 -- | Split the vector into the longest prefix of elements that do not satisfy
528 -- the predicate and the rest.
529 break :: (a -> Bool) -> Vector a -> (Vector a, Vector a)
530 {-# INLINE break #-}
531 break = G.break
532
533 -- Searching
534 -- ---------
535
536 infix 4 `elem`
537 -- | Check whether the vector contains an element
538 elem :: Eq a => a -> Vector a -> Bool
539 {-# INLINE elem #-}
540 elem = G.elem
541
542 infix 4 `notElem`
543 -- | Inverse of `elem`
544 notElem :: Eq a => a -> Vector a -> Bool
545 {-# INLINE notElem #-}
546 notElem = G.notElem
547
548 -- | Yield 'Just' the first element matching the predicate or 'Nothing' if no
549 -- such element exists.
550 find :: (a -> Bool) -> Vector a -> Maybe a
551 {-# INLINE find #-}
552 find = G.find
553
554 -- | Yield 'Just' the index of the first element matching the predicate or
555 -- 'Nothing' if no such element exists.
556 findIndex :: (a -> Bool) -> Vector a -> Maybe Int
557 {-# INLINE findIndex #-}
558 findIndex = G.findIndex
559
560 -- | Yield the indices of elements satisfying the predicate
561 findIndices :: (a -> Bool) -> Vector a -> Vector Int
562 {-# INLINE findIndices #-}
563 findIndices = G.findIndices
564
565 -- | Yield 'Just' the index of the first occurence of the given element or
566 -- 'Nothing' if the vector does not contain the element
567 elemIndex :: Eq a => a -> Vector a -> Maybe Int
568 {-# INLINE elemIndex #-}
569 elemIndex = G.elemIndex
570
571 -- | Yield the indices of all occurences of the given element
572 elemIndices :: Eq a => a -> Vector a -> Vector Int
573 {-# INLINE elemIndices #-}
574 elemIndices = G.elemIndices
575
576 -- Folding
577 -- -------
578
579 -- | Left fold
580 foldl :: (a -> b -> a) -> a -> Vector b -> a
581 {-# INLINE foldl #-}
582 foldl = G.foldl
583
584 -- | Lefgt fold on non-empty vectors
585 foldl1 :: (a -> a -> a) -> Vector a -> a
586 {-# INLINE foldl1 #-}
587 foldl1 = G.foldl1
588
589 -- | Left fold with strict accumulator
590 foldl' :: (a -> b -> a) -> a -> Vector b -> a
591 {-# INLINE foldl' #-}
592 foldl' = G.foldl'
593
594 -- | Left fold on non-empty vectors with strict accumulator
595 foldl1' :: (a -> a -> a) -> Vector a -> a
596 {-# INLINE foldl1' #-}
597 foldl1' = G.foldl1'
598
599 -- | Right fold
600 foldr :: (a -> b -> b) -> b -> Vector a -> b
601 {-# INLINE foldr #-}
602 foldr = G.foldr
603
604 -- | Right fold on non-empty vectors
605 foldr1 :: (a -> a -> a) -> Vector a -> a
606 {-# INLINE foldr1 #-}
607 foldr1 = G.foldr1
608
609 -- | Left fold (function applied to each element and its index)
610 ifoldl :: (a -> Int -> b -> a) -> a -> Vector b -> a
611 {-# INLINE ifoldl #-}
612 ifoldl = G.ifoldl
613
614 -- | Left fold with strict accumulator (function applied to each element and
615 -- its index)
616 ifoldl' :: (a -> Int -> b -> a) -> a -> Vector b -> a
617 {-# INLINE ifoldl' #-}
618 ifoldl' = G.ifoldl'
619
620 -- | Right fold (function applied to each element and its index)
621 ifoldr :: (Int -> a -> b -> b) -> b -> Vector a -> b
622 {-# INLINE ifoldr #-}
623 ifoldr = G.ifoldr
624
625 -- Specialised folds
626 -- -----------------
627
628 all :: (a -> Bool) -> Vector a -> Bool
629 {-# INLINE all #-}
630 all = G.all
631
632 any :: (a -> Bool) -> Vector a -> Bool
633 {-# INLINE any #-}
634 any = G.any
635
636 and :: Vector Bool -> Bool
637 {-# INLINE and #-}
638 and = G.and
639
640 or :: Vector Bool -> Bool
641 {-# INLINE or #-}
642 or = G.or
643
644 sum :: Num a => Vector a -> a
645 {-# INLINE sum #-}
646 sum = G.sum
647
648 product :: Num a => Vector a -> a
649 {-# INLINE product #-}
650 product = G.product
651
652 maximum :: Ord a => Vector a -> a
653 {-# INLINE maximum #-}
654 maximum = G.maximum
655
656 maximumBy :: (a -> a -> Ordering) -> Vector a -> a
657 {-# INLINE maximumBy #-}
658 maximumBy = G.maximumBy
659
660 minimum :: Ord a => Vector a -> a
661 {-# INLINE minimum #-}
662 minimum = G.minimum
663
664 minimumBy :: (a -> a -> Ordering) -> Vector a -> a
665 {-# INLINE minimumBy #-}
666 minimumBy = G.minimumBy
667
668 maxIndex :: Ord a => Vector a -> Int
669 {-# INLINE maxIndex #-}
670 maxIndex = G.maxIndex
671
672 maxIndexBy :: (a -> a -> Ordering) -> Vector a -> Int
673 {-# INLINE maxIndexBy #-}
674 maxIndexBy = G.maxIndexBy
675
676 minIndex :: Ord a => Vector a -> Int
677 {-# INLINE minIndex #-}
678 minIndex = G.minIndex
679
680 minIndexBy :: (a -> a -> Ordering) -> Vector a -> Int
681 {-# INLINE minIndexBy #-}
682 minIndexBy = G.minIndexBy
683
684 -- Unfolding
685 -- ---------
686
687 unfoldr :: (b -> Maybe (a, b)) -> b -> Vector a
688 {-# INLINE unfoldr #-}
689 unfoldr = G.unfoldr
690
691 -- Scans
692 -- -----
693
694 -- | Prefix scan
695 prescanl :: (a -> b -> a) -> a -> Vector b -> Vector a
696 {-# INLINE prescanl #-}
697 prescanl = G.prescanl
698
699 -- | Prefix scan with strict accumulator
700 prescanl' :: (a -> b -> a) -> a -> Vector b -> Vector a
701 {-# INLINE prescanl' #-}
702 prescanl' = G.prescanl'
703
704 -- | Suffix scan
705 postscanl :: (a -> b -> a) -> a -> Vector b -> Vector a
706 {-# INLINE postscanl #-}
707 postscanl = G.postscanl
708
709 -- | Suffix scan with strict accumulator
710 postscanl' :: (a -> b -> a) -> a -> Vector b -> Vector a
711 {-# INLINE postscanl' #-}
712 postscanl' = G.postscanl'
713
714 -- | Haskell-style scan
715 scanl :: (a -> b -> a) -> a -> Vector b -> Vector a
716 {-# INLINE scanl #-}
717 scanl = G.scanl
718
719 -- | Haskell-style scan with strict accumulator
720 scanl' :: (a -> b -> a) -> a -> Vector b -> Vector a
721 {-# INLINE scanl' #-}
722 scanl' = G.scanl'
723
724 -- | Scan over a non-empty 'Vector'
725 scanl1 :: (a -> a -> a) -> Vector a -> Vector a
726 {-# INLINE scanl1 #-}
727 scanl1 = G.scanl1
728
729 -- | Scan over a non-empty 'Vector' with a strict accumulator
730 scanl1' :: (a -> a -> a) -> Vector a -> Vector a
731 {-# INLINE scanl1' #-}
732 scanl1' = G.scanl1'
733
734 -- Enumeration
735 -- -----------
736
737 enumFromTo :: Enum a => a -> a -> Vector a
738 {-# INLINE enumFromTo #-}
739 enumFromTo = G.enumFromTo
740
741 enumFromThenTo :: Enum a => a -> a -> a -> Vector a
742 {-# INLINE enumFromThenTo #-}
743 enumFromThenTo = G.enumFromThenTo
744
745 -- Conversion to/from lists
746 -- ------------------------
747
748 -- | Convert a vector to a list
749 toList :: Vector a -> [a]
750 {-# INLINE toList #-}
751 toList = G.toList
752
753 -- | Convert a list to a vector
754 fromList :: [a] -> Vector a
755 {-# INLINE fromList #-}
756 fromList = G.fromList
757