
And just remember filtered is only a valid traversal if you don't change
the number of targets with the modification function!
On 18 August 2014 14:17, Elise Huard
Hi Daniel,
thanks for your answer. That looks like something that might work - however, having never worked with Optics, I'm not entirely sure whether I'm doing it right, getting an error: *Main Graphics.Rendering.OpenGL Control.Lens> :t (liveforms . filtered (colliding p))
<interactive>:1:14: Couldn't match type _Lifeform_ with _[Lifeform]_ Expected type: (Lifeform -> f Lifeform) -> [Lifeform] -> f [Lifeform] Actual type: Optic' (->) f Lifeform Lifeform In the second argument of _(.)_, namely _filtered ((flip colliding) p)_ In the expression: (liveforms . filtered ((flip colliding) p)) *Main Graphics.Rendering.OpenGL Control.Lens>
Also, may I ask what the '&' is in your proposed solution? Thanks,
Elise
On 18 August 2014 13:30, Daniel Trstenjak
wrote: Hi Elise,
I'm not quite sure if I completely understood your use case, but if you only want to modify the lifeforms that are colliding with the player, then you could have something like:
world & liveforms . filtered (collidingWith player) %~ \liveform ->
...
with
liveforms :: Lens' World [Lifeform]
collidingWith :: Player -> Lifeform -> Bool
I would consider this as a quite nice solution.
Greetings, Daniel _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners