Using a map with a function

I have 2 functions

accelerate :: Float -> [Particle] -> [Particle]
accelerateParticle :: Float -> Particle -> [Particle] -> Particle

      

and what I am trying to achieve is for each item in [Particle]

a function is applied accelerateParticle

. The problem I am facing is that the function is accelerateParticle

based on using the original [Particle]

, which is set with acceleration. I was thinking about using a card like this.

map (\particle -> accelerateParticle Float particle [Particle]) [Particle]

but I'm not really sure if this is the correct format.

+3


source to share


1 answer


You may be looking for the following:

accelerate :: Float -> [Particle] -> [Particle]
accelerate x ps = map (\p -> accelerateParticle x p ps) ps

      



Note that the list of all particles is ps

used both for map

above and as a parameter accelerateParticle

.

+6


source







All Articles