Ok. I'm not asking for a plssendcodezkthx. But I am somewhat new to FP and I'm trying to figure out how to do this, because I know the code I have won't accomplish what I'd like to achieve. So all arguments about optimization aside, here is my code Then I'll explain.
let moveBoids boids =
boids |> List.map (fun(boid) ->
let others = List.filter (fun(b) -> b.Id <> boid.Id) boids
let positions = others |> List.map(fun(b2) -> b2.Position)
let velocities = others |> List.map(fun(b3) -> b3.Velocity)
let c = centerWithFlock (boid, positions)
let d = distanceFromFlock (boid, positions)
let v = matchVelocityWithFlock (boid, velocities)
let v2 = List.fold_right (addVector) [c; d; v] {X=0.; Y=0.; Z=0.}
let p = addVector boid.Position v2
{boid with Position=p; Velocity=v2})
I'm trying to map my list of boids to a new list of boids. Sounds easy, except I'm pretty sure if I run this, each boid will only change according to the original list, not to the list as each boid updates itself. How the hell can I do that using a map style call? Should I not even be using a map style call? I know my function is closed over my boids list, so how can I pass the updated list to the next call?
Word.