File tree Expand file tree Collapse file tree 5 files changed +85
-0
lines changed Expand file tree Collapse file tree 5 files changed +85
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ module Data.Vector (
60
60
61
61
-- ** Unfolding
62
62
unfoldr , unfoldrN ,
63
+ unfoldrM , unfoldrNM ,
63
64
constructN , constructrN ,
64
65
65
66
-- ** Enumeration
@@ -633,6 +634,22 @@ unfoldrN :: Int -> (b -> Maybe (a, b)) -> b -> Vector a
633
634
{-# INLINE unfoldrN #-}
634
635
unfoldrN = G. unfoldrN
635
636
637
+ -- | /O(n)/ Construct a vector by repeatedly applying the monadic
638
+ -- generator function to a seed. The generator function yields 'Just'
639
+ -- the next element and the new seed or 'Nothing' if there are no more
640
+ -- elements.
641
+ unfoldrM :: (Monad m ) => (b -> m (Maybe (a , b ))) -> b -> m (Vector a )
642
+ {-# INLINE unfoldrM #-}
643
+ unfoldrM = G. unfoldrM
644
+
645
+ -- | /O(n)/ Construct a vector by repeatedly applying the monadic
646
+ -- generator function to a seed. The generator function yields 'Just'
647
+ -- the next element and the new seed or 'Nothing' if there are no more
648
+ -- elements.
649
+ unfoldrNM :: (Monad m ) => Int -> (b -> m (Maybe (a , b ))) -> b -> m (Vector a )
650
+ {-# INLINE unfoldrNM #-}
651
+ unfoldrNM = G. unfoldrNM
652
+
636
653
-- | /O(n)/ Construct a vector with @n@ elements by repeatedly applying the
637
654
-- generator function to the already constructed part of the vector.
638
655
--
Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ module Data.Vector.Generic (
43
43
44
44
-- ** Unfolding
45
45
unfoldr , unfoldrN ,
46
+ unfoldrM , unfoldrNM ,
46
47
constructN , constructrN ,
47
48
48
49
-- ** Enumeration
@@ -551,6 +552,22 @@ unfoldrN :: Vector v a => Int -> (b -> Maybe (a, b)) -> b -> v a
551
552
{-# INLINE unfoldrN #-}
552
553
unfoldrN n f = unstream . Bundle. unfoldrN n f
553
554
555
+ -- | /O(n)/ Construct a vector by repeatedly applying the monadic
556
+ -- generator function to a seed. The generator function yields 'Just'
557
+ -- the next element and the new seed or 'Nothing' if there are no more
558
+ -- elements.
559
+ unfoldrM :: (Monad m , Vector v a ) => (b -> m (Maybe (a , b ))) -> b -> m (v a )
560
+ {-# INLINE unfoldrM #-}
561
+ unfoldrM f = unstreamM . MBundle. unfoldrM f
562
+
563
+ -- | /O(n)/ Construct a vector by repeatedly applying the monadic
564
+ -- generator function to a seed. The generator function yields 'Just'
565
+ -- the next element and the new seed or 'Nothing' if there are no more
566
+ -- elements.
567
+ unfoldrNM :: (Monad m , Vector v a ) => Int -> (b -> m (Maybe (a , b ))) -> b -> m (v a )
568
+ {-# INLINE unfoldrNM #-}
569
+ unfoldrNM n f = unstreamM . MBundle. unfoldrNM n f
570
+
554
571
-- | /O(n)/ Construct a vector with @n@ elements by repeatedly applying the
555
572
-- generator function to the already constructed part of the vector.
556
573
--
Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ module Data.Vector.Primitive (
46
46
47
47
-- ** Unfolding
48
48
unfoldr , unfoldrN ,
49
+ unfoldrM , unfoldrNM ,
49
50
constructN , constructrN ,
50
51
51
52
-- ** Enumeration
@@ -516,6 +517,22 @@ unfoldrN :: Prim a => Int -> (b -> Maybe (a, b)) -> b -> Vector a
516
517
{-# INLINE unfoldrN #-}
517
518
unfoldrN = G. unfoldrN
518
519
520
+ -- | /O(n)/ Construct a vector by repeatedly applying the monadic
521
+ -- generator function to a seed. The generator function yields 'Just'
522
+ -- the next element and the new seed or 'Nothing' if there are no more
523
+ -- elements.
524
+ unfoldrM :: (Monad m , Prim a ) => (b -> m (Maybe (a , b ))) -> b -> m (Vector a )
525
+ {-# INLINE unfoldrM #-}
526
+ unfoldrM = G. unfoldrM
527
+
528
+ -- | /O(n)/ Construct a vector by repeatedly applying the monadic
529
+ -- generator function to a seed. The generator function yields 'Just'
530
+ -- the next element and the new seed or 'Nothing' if there are no more
531
+ -- elements.
532
+ unfoldrNM :: (Monad m , Prim a ) => Int -> (b -> m (Maybe (a , b ))) -> b -> m (Vector a )
533
+ {-# INLINE unfoldrNM #-}
534
+ unfoldrNM = G. unfoldrNM
535
+
519
536
-- | /O(n)/ Construct a vector with @n@ elements by repeatedly applying the
520
537
-- generator function to the already constructed part of the vector.
521
538
--
Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ module Data.Vector.Storable (
43
43
44
44
-- ** Unfolding
45
45
unfoldr , unfoldrN ,
46
+ unfoldrM , unfoldrNM ,
46
47
constructN , constructrN ,
47
48
48
49
-- ** Enumeration
@@ -526,6 +527,22 @@ unfoldrN :: Storable a => Int -> (b -> Maybe (a, b)) -> b -> Vector a
526
527
{-# INLINE unfoldrN #-}
527
528
unfoldrN = G. unfoldrN
528
529
530
+ -- | /O(n)/ Construct a vector by repeatedly applying the monadic
531
+ -- generator function to a seed. The generator function yields 'Just'
532
+ -- the next element and the new seed or 'Nothing' if there are no more
533
+ -- elements.
534
+ unfoldrM :: (Monad m , Storable a ) => (b -> m (Maybe (a , b ))) -> b -> m (Vector a )
535
+ {-# INLINE unfoldrM #-}
536
+ unfoldrM = G. unfoldrM
537
+
538
+ -- | /O(n)/ Construct a vector by repeatedly applying the monadic
539
+ -- generator function to a seed. The generator function yields 'Just'
540
+ -- the next element and the new seed or 'Nothing' if there are no more
541
+ -- elements.
542
+ unfoldrNM :: (Monad m , Storable a ) => Int -> (b -> m (Maybe (a , b ))) -> b -> m (Vector a )
543
+ {-# INLINE unfoldrNM #-}
544
+ unfoldrNM = G. unfoldrNM
545
+
529
546
-- | /O(n)/ Construct a vector with @n@ elements by repeatedly applying the
530
547
-- generator function to the already constructed part of the vector.
531
548
--
Original file line number Diff line number Diff line change @@ -66,6 +66,7 @@ module Data.Vector.Unboxed (
66
66
67
67
-- ** Unfolding
68
68
unfoldr , unfoldrN ,
69
+ unfoldrM , unfoldrNM ,
69
70
constructN , constructrN ,
70
71
71
72
-- ** Enumeration
@@ -495,6 +496,22 @@ unfoldrN :: Unbox a => Int -> (b -> Maybe (a, b)) -> b -> Vector a
495
496
{-# INLINE unfoldrN #-}
496
497
unfoldrN = G. unfoldrN
497
498
499
+ -- | /O(n)/ Construct a vector by repeatedly applying the monadic
500
+ -- generator function to a seed. The generator function yields 'Just'
501
+ -- the next element and the new seed or 'Nothing' if there are no more
502
+ -- elements.
503
+ unfoldrM :: (Monad m , Unbox a ) => (b -> m (Maybe (a , b ))) -> b -> m (Vector a )
504
+ {-# INLINE unfoldrM #-}
505
+ unfoldrM = G. unfoldrM
506
+
507
+ -- | /O(n)/ Construct a vector by repeatedly applying the monadic
508
+ -- generator function to a seed. The generator function yields 'Just'
509
+ -- the next element and the new seed or 'Nothing' if there are no more
510
+ -- elements.
511
+ unfoldrNM :: (Monad m , Unbox a ) => Int -> (b -> m (Maybe (a , b ))) -> b -> m (Vector a )
512
+ {-# INLINE unfoldrNM #-}
513
+ unfoldrNM = G. unfoldrNM
514
+
498
515
-- | /O(n)/ Construct a vector with @n@ elements by repeatedly applying the
499
516
-- generator function to the already constructed part of the vector.
500
517
--
You can’t perform that action at this time.
0 commit comments