iterateN
Constructs a sequence by repeated application of a
function to a seed value.
iterateN n f x = fromList (Prelude.take n (Prelude.iterate f x))
O(n) Apply the function <math> times to an initial value,
producing a vector of length <math>. The 0th element will
contain the initial value, which is why there is one less function
application than the number of elements in the produced vector.
<math>
Examples
>>> import qualified Data.Vector as V
>>> V.iterateN 0 undefined undefined :: V.Vector String
[]
>>> V.iterateN 4 (\x -> x <> x) "Hi"
["Hi","HiHi","HiHiHiHi","HiHiHiHiHiHiHiHi"]
O(n) Apply function <math> times to an initial value,
producing a pure bundle of exact length <math>. Zeroth element
will contain the initial value.
O(n) Apply function <math> times to an initial value,
producing a monadic bundle of exact length <math>. Zeroth
element will contain the initial value.
O(n) Apply the function <math> times to an initial value,
producing a vector of length <math>. The 0th element will
contain the initial value, which is why there is one less function
application than the number of elements in the produced vector.
<math>
O(n) Apply the function <math> times to an initial value,
producing a vector of length <math>. The 0th element will
contain the initial value, which is why there is one less function
application than the number of elements in the produced vector.
<math>
Examples
>>> import qualified Data.Vector.Primitive as VP
>>> VP.iterateN 0 undefined undefined :: VP.Vector Int
[]
>>> VP.iterateN 26 succ 'a'
"abcdefghijklmnopqrstuvwxyz"
O(n) Apply the function <math> times to an initial value,
producing a vector of length <math>. The 0th element will
contain the initial value, which is why there is one less function
application than the number of elements in the produced vector.
<math>
Examples
>>> import qualified Data.Vector.Storable as VS
>>> VS.iterateN 0 undefined undefined :: VS.Vector Int
[]
>>> VS.iterateN 26 succ 'a'
"abcdefghijklmnopqrstuvwxyz"
O(n) Apply the function <math> times to an initial value,
producing a vector of length <math>. The 0th element will
contain the initial value, which is why there is one less function
application than the number of elements in the produced vector.
<math>
Examples
>>> import qualified Data.Vector.Unboxed as VU
>>> VU.iterateN 0 undefined undefined :: VU.Vector Int
[]
>>> VU.iterateN 3 (\(i, c) -> (pred i, succ c)) (0 :: Int, 'a')
[(0,'a'),(-1,'b'),(-2,'c')]
iterateN n f x returns the list of the first n
iterates of f starting at x, that is, the list
[x, f x, f (f x), ...] of length n. (Note that the
last element of the list will be f applied to x
(n-1) times.)
O(n) Apply function <math> times to an initial value,
producing a vector of length <math>. Zeroth element will contain
the initial value, that's why there is one less function application
than the number of elements in the produced vector.
<math>
O(n) Apply function <math> times to an initial value,
producing a vector of length <math>. Zeroth element will contain
the initial value, that's why there is one less function application
than the number of elements in the produced vector.
<math>
Examples
>>> import qualified Data.Vector as V
>>> V.iterateN 0 undefined undefined :: V.Vector String
[]
>>> V.iterateN 4 (\x -> x <> x) "Hi"
["Hi","HiHi","HiHiHiHi","HiHiHiHiHiHiHiHi"]
O(n) Apply function <math> times to an initial value,
producing a vector of length <math>. Zeroth element will contain
the initial value, that's why there is one less function application
than the number of elements in the produced vector.
<math>
Examples
>>> import qualified Data.Vector.Storable as VS
>>> VS.iterateN 0 undefined undefined :: VS.Vector Int
[]
>>> VS.iterateN 26 succ 'a'
"abcdefghijklmnopqrstuvwxyz"
O(n) Apply function <math> times to an initial value,
producing a vector of length <math>. Zeroth element will contain
the initial value, that's why there is one less function application
than the number of elements in the produced vector.
<math>
Examples
>>> import qualified Data.Vector.Unboxed as VU
>>> VU.iterateN 0 undefined undefined :: VU.Vector Int
[]
>>> VU.iterateN 3 (\(i, c) -> (pred i, succ c)) (0 :: Int, 'a')
[(0,'a'),(-1,'b'),(-2,'c')]
O(n) iterateN n f x is a
Vector of
length
n where the elements are generated by repeated
application of
f, starting at
x.
Apply a function
n times to a value and construct an array
where each consecutive element is the result of an additional
application of this function. The zeroth element is the original
value.
iterateN 5 (+ 1) 0 = fromListN 5 [0,1,2,3,4]
O(n) Apply the function n times to a value. Zeroth
element is the original value. The length is inferred from the type.
O(n) Apply function n times to value. Zeroth element
is original value. The length is inferred from the type.
O(n) Apply the function n times to a value. Zeroth
element is original value. The length is inferred from the type.
O(n) Apply function n times to value. Zeroth element
is original value. The length is inferred from the type.
O(n) Apply the function n times to a value. Zeroth
element is original value. The length is inferred from the type.
Sequentially iterate over each cell in the array in the row-major
order while continuously aplying the accumulator at each step.
Example
>>> import Data.Massiv.Array
>>> iterateN (Sz2 2 10) succ (10 :: Int)
Array DL Seq (Sz (2 :. 10))
[ [ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ]
, [ 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 ]
]
Build a vector by repeatedly applying a function to a seed value.
Compare to
iterateN