I have a function f :: (a -> a) -> a -> ((a -> a), a)
. (In the specific case a
is Int
, but that is irrelevant.)
I have a function initial :: a -> a
, and a list of inputs (inputs :: [a]
).
I need to apply f
to all the elements of inputs
, but, for each, I need to take the fst
part of the output of the previous iteration and feed it as the (a -> a)
part of the input for the next. As the output, I need to have a list of type [a]
, which is the snd
part of the outputs of each iteration.
How can I recursively apply f
to the fst
part of the output and the elements of inputs
, while building up a list of the intermediate snd
parts of the output?