Add unsafeInit and unsafeTail
[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,
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 unsafeInit :: Vector a -> Vector a
286 {-# INLINE unsafeInit #-}
287 unsafeInit = G.unsafeInit
288
289 unsafeTail :: Vector a -> Vector a
290 {-# INLINE unsafeTail #-}
291 unsafeTail = G.unsafeTail
292
293 -- | Unsafely yield a part of the vector without copying it and without
294 -- performing bounds checks.
295 unsafeSlice :: Int -- ^ starting index
296 -> Int -- ^ length
297 -> Vector a
298 -> Vector a
299 {-# INLINE unsafeSlice #-}
300 unsafeSlice = G.unsafeSlice
301
302 -- Permutations
303 -- ------------
304
305 unsafeAccum :: (a -> b -> a) -> Vector a -> [(Int,b)] -> Vector a
306 {-# INLINE unsafeAccum #-}
307 unsafeAccum = G.unsafeAccum
308
309 unsafeAccumulate :: (a -> b -> a) -> Vector a -> Vector (Int,b) -> Vector a
310 {-# INLINE unsafeAccumulate #-}
311 unsafeAccumulate = G.unsafeAccumulate
312
313 unsafeAccumulate_
314 :: (a -> b -> a) -> Vector a -> Vector Int -> Vector b -> Vector a
315 {-# INLINE unsafeAccumulate_ #-}
316 unsafeAccumulate_ = G.unsafeAccumulate_
317
318 accum :: (a -> b -> a) -> Vector a -> [(Int,b)] -> Vector a
319 {-# INLINE accum #-}
320 accum = G.accum
321
322 accumulate :: (a -> b -> a) -> Vector a -> Vector (Int,b) -> Vector a
323 {-# INLINE accumulate #-}
324 accumulate = G.accumulate
325
326 accumulate_ :: (a -> b -> a) -> Vector a -> Vector Int -> Vector b -> Vector a
327 {-# INLINE accumulate_ #-}
328 accumulate_ = G.accumulate_
329
330 unsafeUpd :: Vector a -> [(Int, a)] -> Vector a
331 {-# INLINE unsafeUpd #-}
332 unsafeUpd = G.unsafeUpd
333
334 unsafeUpdate :: Vector a -> Vector (Int, a) -> Vector a
335 {-# INLINE unsafeUpdate #-}
336 unsafeUpdate = G.unsafeUpdate
337
338 unsafeUpdate_ :: Vector a -> Vector Int -> Vector a -> Vector a
339 {-# INLINE unsafeUpdate_ #-}
340 unsafeUpdate_ = G.unsafeUpdate_
341
342 (//) :: Vector a -> [(Int, a)] -> Vector a
343 {-# INLINE (//) #-}
344 (//) = (G.//)
345
346 update :: Vector a -> Vector (Int, a) -> Vector a
347 {-# INLINE update #-}
348 update = G.update
349
350 update_ :: Vector a -> Vector Int -> Vector a -> Vector a
351 {-# INLINE update_ #-}
352 update_ = G.update_
353
354 backpermute :: Vector a -> Vector Int -> Vector a
355 {-# INLINE backpermute #-}
356 backpermute = G.backpermute
357
358 reverse :: Vector a -> Vector a
359 {-# INLINE reverse #-}
360 reverse = G.reverse
361
362 -- Mapping
363 -- -------
364
365 -- | Map a function over a vector
366 map :: (a -> b) -> Vector a -> Vector b
367 {-# INLINE map #-}
368 map = G.map
369
370 -- | Apply a function to every index/value pair
371 imap :: (Int -> a -> b) -> Vector a -> Vector b
372 {-# INLINE imap #-}
373 imap = G.imap
374
375 concatMap :: (a -> Vector b) -> Vector a -> Vector b
376 {-# INLINE concatMap #-}
377 concatMap = G.concatMap
378
379 -- Zipping/unzipping
380 -- -----------------
381
382 -- | Zip two vectors with the given function.
383 zipWith :: (a -> b -> c) -> Vector a -> Vector b -> Vector c
384 {-# INLINE zipWith #-}
385 zipWith = G.zipWith
386
387 -- | Zip three vectors with the given function.
388 zipWith3 :: (a -> b -> c -> d) -> Vector a -> Vector b -> Vector c -> Vector d
389 {-# INLINE zipWith3 #-}
390 zipWith3 = G.zipWith3
391
392 zipWith4 :: (a -> b -> c -> d -> e)
393 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
394 {-# INLINE zipWith4 #-}
395 zipWith4 = G.zipWith4
396
397 zipWith5 :: (a -> b -> c -> d -> e -> f)
398 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
399 -> Vector f
400 {-# INLINE zipWith5 #-}
401 zipWith5 = G.zipWith5
402
403 zipWith6 :: (a -> b -> c -> d -> e -> f -> g)
404 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
405 -> Vector f -> Vector g
406 {-# INLINE zipWith6 #-}
407 zipWith6 = G.zipWith6
408
409 -- | Zip two vectors and their indices with the given function.
410 izipWith :: (Int -> a -> b -> c) -> Vector a -> Vector b -> Vector c
411 {-# INLINE izipWith #-}
412 izipWith = G.izipWith
413
414 -- | Zip three vectors and their indices with the given function.
415 izipWith3 :: (Int -> a -> b -> c -> d)
416 -> Vector a -> Vector b -> Vector c -> Vector d
417 {-# INLINE izipWith3 #-}
418 izipWith3 = G.izipWith3
419
420 izipWith4 :: (Int -> a -> b -> c -> d -> e)
421 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
422 {-# INLINE izipWith4 #-}
423 izipWith4 = G.izipWith4
424
425 izipWith5 :: (Int -> a -> b -> c -> d -> e -> f)
426 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
427 -> Vector f
428 {-# INLINE izipWith5 #-}
429 izipWith5 = G.izipWith5
430
431 izipWith6 :: (Int -> a -> b -> c -> d -> e -> f -> g)
432 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
433 -> Vector f -> Vector g
434 {-# INLINE izipWith6 #-}
435 izipWith6 = G.izipWith6
436
437 zip :: Vector a -> Vector b -> Vector (a, b)
438 {-# INLINE zip #-}
439 zip = G.zip
440
441 zip3 :: Vector a -> Vector b -> Vector c -> Vector (a, b, c)
442 {-# INLINE zip3 #-}
443 zip3 = G.zip3
444
445 zip4 :: Vector a -> Vector b -> Vector c -> Vector d
446 -> Vector (a, b, c, d)
447 {-# INLINE zip4 #-}
448 zip4 = G.zip4
449
450 zip5 :: Vector a -> Vector b -> Vector c -> Vector d -> Vector e
451 -> Vector (a, b, c, d, e)
452 {-# INLINE zip5 #-}
453 zip5 = G.zip5
454
455 zip6 :: Vector a -> Vector b -> Vector c -> Vector d -> Vector e -> Vector f
456 -> Vector (a, b, c, d, e, f)
457 {-# INLINE zip6 #-}
458 zip6 = G.zip6
459
460 unzip :: Vector (a, b) -> (Vector a, Vector b)
461 {-# INLINE unzip #-}
462 unzip = G.unzip
463
464 unzip3 :: Vector (a, b, c) -> (Vector a, Vector b, Vector c)
465 {-# INLINE unzip3 #-}
466 unzip3 = G.unzip3
467
468 unzip4 :: Vector (a, b, c, d) -> (Vector a, Vector b, Vector c, Vector d)
469 {-# INLINE unzip4 #-}
470 unzip4 = G.unzip4
471
472 unzip5 :: Vector (a, b, c, d, e)
473 -> (Vector a, Vector b, Vector c, Vector d, Vector e)
474 {-# INLINE unzip5 #-}
475 unzip5 = G.unzip5
476
477 unzip6 :: Vector (a, b, c, d, e, f)
478 -> (Vector a, Vector b, Vector c, Vector d, Vector e, Vector f)
479 {-# INLINE unzip6 #-}
480 unzip6 = G.unzip6
481
482 -- Filtering
483 -- ---------
484
485 -- | Drop elements which do not satisfy the predicate
486 filter :: (a -> Bool) -> Vector a -> Vector a
487 {-# INLINE filter #-}
488 filter = G.filter
489
490 -- | Drop elements that do not satisfy the predicate (applied to values and
491 -- their indices)
492 ifilter :: (Int -> a -> Bool) -> Vector a -> Vector a
493 {-# INLINE ifilter #-}
494 ifilter = G.ifilter
495
496 -- | Yield the longest prefix of elements satisfying the predicate.
497 takeWhile :: (a -> Bool) -> Vector a -> Vector a
498 {-# INLINE takeWhile #-}
499 takeWhile = G.takeWhile
500
501 -- | Drop the longest prefix of elements that satisfy the predicate.
502 dropWhile :: (a -> Bool) -> Vector a -> Vector a
503 {-# INLINE dropWhile #-}
504 dropWhile = G.dropWhile
505
506 -- | Split the vector in two parts, the first one containing those elements
507 -- that satisfy the predicate and the second one those that don't. The order
508 -- of the elements is not preserved.
509 unstablePartition :: (a -> Bool) -> Vector a -> (Vector a, Vector a)
510 {-# INLINE unstablePartition #-}
511 unstablePartition = G.unstablePartition
512
513 -- | Split the vector into the longest prefix of elements that satisfy the
514 -- predicate and the rest.
515 span :: (a -> Bool) -> Vector a -> (Vector a, Vector a)
516 {-# INLINE span #-}
517 span = G.span
518
519 -- | Split the vector into the longest prefix of elements that do not satisfy
520 -- the predicate and the rest.
521 break :: (a -> Bool) -> Vector a -> (Vector a, Vector a)
522 {-# INLINE break #-}
523 break = G.break
524
525 -- Searching
526 -- ---------
527
528 infix 4 `elem`
529 -- | Check whether the vector contains an element
530 elem :: Eq a => a -> Vector a -> Bool
531 {-# INLINE elem #-}
532 elem = G.elem
533
534 infix 4 `notElem`
535 -- | Inverse of `elem`
536 notElem :: Eq a => a -> Vector a -> Bool
537 {-# INLINE notElem #-}
538 notElem = G.notElem
539
540 -- | Yield 'Just' the first element matching the predicate or 'Nothing' if no
541 -- such element exists.
542 find :: (a -> Bool) -> Vector a -> Maybe a
543 {-# INLINE find #-}
544 find = G.find
545
546 -- | Yield 'Just' the index of the first element matching the predicate or
547 -- 'Nothing' if no such element exists.
548 findIndex :: (a -> Bool) -> Vector a -> Maybe Int
549 {-# INLINE findIndex #-}
550 findIndex = G.findIndex
551
552 -- | Yield the indices of elements satisfying the predicate
553 findIndices :: (a -> Bool) -> Vector a -> Vector Int
554 {-# INLINE findIndices #-}
555 findIndices = G.findIndices
556
557 -- | Yield 'Just' the index of the first occurence of the given element or
558 -- 'Nothing' if the vector does not contain the element
559 elemIndex :: Eq a => a -> Vector a -> Maybe Int
560 {-# INLINE elemIndex #-}
561 elemIndex = G.elemIndex
562
563 -- | Yield the indices of all occurences of the given element
564 elemIndices :: Eq a => a -> Vector a -> Vector Int
565 {-# INLINE elemIndices #-}
566 elemIndices = G.elemIndices
567
568 -- Folding
569 -- -------
570
571 -- | Left fold
572 foldl :: (a -> b -> a) -> a -> Vector b -> a
573 {-# INLINE foldl #-}
574 foldl = G.foldl
575
576 -- | Lefgt fold on non-empty vectors
577 foldl1 :: (a -> a -> a) -> Vector a -> a
578 {-# INLINE foldl1 #-}
579 foldl1 = G.foldl1
580
581 -- | Left fold with strict accumulator
582 foldl' :: (a -> b -> a) -> a -> Vector b -> a
583 {-# INLINE foldl' #-}
584 foldl' = G.foldl'
585
586 -- | Left fold on non-empty vectors with strict accumulator
587 foldl1' :: (a -> a -> a) -> Vector a -> a
588 {-# INLINE foldl1' #-}
589 foldl1' = G.foldl1'
590
591 -- | Right fold
592 foldr :: (a -> b -> b) -> b -> Vector a -> b
593 {-# INLINE foldr #-}
594 foldr = G.foldr
595
596 -- | Right fold on non-empty vectors
597 foldr1 :: (a -> a -> a) -> Vector a -> a
598 {-# INLINE foldr1 #-}
599 foldr1 = G.foldr1
600
601 -- | Left fold (function applied to each element and its index)
602 ifoldl :: (a -> Int -> b -> a) -> a -> Vector b -> a
603 {-# INLINE ifoldl #-}
604 ifoldl = G.ifoldl
605
606 -- | Left fold with strict accumulator (function applied to each element and
607 -- its index)
608 ifoldl' :: (a -> Int -> b -> a) -> a -> Vector b -> a
609 {-# INLINE ifoldl' #-}
610 ifoldl' = G.ifoldl'
611
612 -- | Right fold (function applied to each element and its index)
613 ifoldr :: (Int -> a -> b -> b) -> b -> Vector a -> b
614 {-# INLINE ifoldr #-}
615 ifoldr = G.ifoldr
616
617 -- Specialised folds
618 -- -----------------
619
620 all :: (a -> Bool) -> Vector a -> Bool
621 {-# INLINE all #-}
622 all = G.all
623
624 any :: (a -> Bool) -> Vector a -> Bool
625 {-# INLINE any #-}
626 any = G.any
627
628 and :: Vector Bool -> Bool
629 {-# INLINE and #-}
630 and = G.and
631
632 or :: Vector Bool -> Bool
633 {-# INLINE or #-}
634 or = G.or
635
636 sum :: Num a => Vector a -> a
637 {-# INLINE sum #-}
638 sum = G.sum
639
640 product :: Num a => Vector a -> a
641 {-# INLINE product #-}
642 product = G.product
643
644 maximum :: Ord a => Vector a -> a
645 {-# INLINE maximum #-}
646 maximum = G.maximum
647
648 maximumBy :: (a -> a -> Ordering) -> Vector a -> a
649 {-# INLINE maximumBy #-}
650 maximumBy = G.maximumBy
651
652 minimum :: Ord a => Vector a -> a
653 {-# INLINE minimum #-}
654 minimum = G.minimum
655
656 minimumBy :: (a -> a -> Ordering) -> Vector a -> a
657 {-# INLINE minimumBy #-}
658 minimumBy = G.minimumBy
659
660 maxIndex :: Ord a => Vector a -> Int
661 {-# INLINE maxIndex #-}
662 maxIndex = G.maxIndex
663
664 maxIndexBy :: (a -> a -> Ordering) -> Vector a -> Int
665 {-# INLINE maxIndexBy #-}
666 maxIndexBy = G.maxIndexBy
667
668 minIndex :: Ord a => Vector a -> Int
669 {-# INLINE minIndex #-}
670 minIndex = G.minIndex
671
672 minIndexBy :: (a -> a -> Ordering) -> Vector a -> Int
673 {-# INLINE minIndexBy #-}
674 minIndexBy = G.minIndexBy
675
676 -- Unfolding
677 -- ---------
678
679 unfoldr :: (b -> Maybe (a, b)) -> b -> Vector a
680 {-# INLINE unfoldr #-}
681 unfoldr = G.unfoldr
682
683 -- Scans
684 -- -----
685
686 -- | Prefix scan
687 prescanl :: (a -> b -> a) -> a -> Vector b -> Vector a
688 {-# INLINE prescanl #-}
689 prescanl = G.prescanl
690
691 -- | Prefix scan with strict accumulator
692 prescanl' :: (a -> b -> a) -> a -> Vector b -> Vector a
693 {-# INLINE prescanl' #-}
694 prescanl' = G.prescanl'
695
696 -- | Suffix scan
697 postscanl :: (a -> b -> a) -> a -> Vector b -> Vector a
698 {-# INLINE postscanl #-}
699 postscanl = G.postscanl
700
701 -- | Suffix scan with strict accumulator
702 postscanl' :: (a -> b -> a) -> a -> Vector b -> Vector a
703 {-# INLINE postscanl' #-}
704 postscanl' = G.postscanl'
705
706 -- | Haskell-style scan
707 scanl :: (a -> b -> a) -> a -> Vector b -> Vector a
708 {-# INLINE scanl #-}
709 scanl = G.scanl
710
711 -- | Haskell-style scan with strict accumulator
712 scanl' :: (a -> b -> a) -> a -> Vector b -> Vector a
713 {-# INLINE scanl' #-}
714 scanl' = G.scanl'
715
716 -- | Scan over a non-empty 'Vector'
717 scanl1 :: (a -> a -> a) -> Vector a -> Vector a
718 {-# INLINE scanl1 #-}
719 scanl1 = G.scanl1
720
721 -- | Scan over a non-empty 'Vector' with a strict accumulator
722 scanl1' :: (a -> a -> a) -> Vector a -> Vector a
723 {-# INLINE scanl1' #-}
724 scanl1' = G.scanl1'
725
726 -- Enumeration
727 -- -----------
728
729 enumFromTo :: Enum a => a -> a -> Vector a
730 {-# INLINE enumFromTo #-}
731 enumFromTo = G.enumFromTo
732
733 enumFromThenTo :: Enum a => a -> a -> a -> Vector a
734 {-# INLINE enumFromThenTo #-}
735 enumFromThenTo = G.enumFromThenTo
736
737 -- Conversion to/from lists
738 -- ------------------------
739
740 -- | Convert a vector to a list
741 toList :: Vector a -> [a]
742 {-# INLINE toList #-}
743 toList = G.toList
744
745 -- | Convert a list to a vector
746 fromList :: [a] -> Vector a
747 {-# INLINE fromList #-}
748 fromList = G.fromList
749