<div dir="ltr">And just remember filtered is only a valid traversal if you don't change the number of targets with the modification function!</div><div class="gmail_extra"><br><br><div class="gmail_quote">On 18 August 2014 14:17, Elise Huard <span dir="ltr"><<a href="mailto:haskell@elisehuard.be" target="_blank">haskell@elisehuard.be</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Daniel,<br>
<br>
thanks for your answer. That looks like something that might work -<br>
however,  having never worked with Optics, I'm not entirely sure<br>
whether I'm doing it right, getting an error:<br>
*Main Graphics.Rendering.OpenGL Control.Lens> :t (liveforms . filtered<br>
(colliding p))<br>
<br>
<interactive>:1:14:<br>
    Couldn't match type _Lifeform_ with _[Lifeform]_<br>
    Expected type: (Lifeform -> f Lifeform)<br>
                   -> [Lifeform] -> f [Lifeform]<br>
      Actual type: Optic' (->) f Lifeform Lifeform<br>
    In the second argument of _(.)_, namely<br>
      _filtered ((flip colliding) p)_<br>
    In the expression: (liveforms . filtered ((flip colliding) p))<br>
*Main Graphics.Rendering.OpenGL Control.Lens><br>
<br>
Also, may I ask what the '&' is in your proposed solution?<br>
Thanks,<br>
<br>
Elise<br>
<div class="HOEnZb"><div class="h5"><br>
On 18 August 2014 13:30, Daniel Trstenjak <<a href="mailto:daniel.trstenjak@gmail.com">daniel.trstenjak@gmail.com</a>> wrote:<br>
><br>
> Hi Elise,<br>
><br>
> I'm not quite sure if I completely understood your use case, but if<br>
> you only want to modify the lifeforms that are colliding with the player,<br>
> then you could have something like:<br>
><br>
>    world & liveforms . filtered (collidingWith player) %~ \liveform -> ...<br>
><br>
> with<br>
><br>
>    liveforms :: Lens' World [Lifeform]<br>
><br>
>    collidingWith :: Player -> Lifeform -> Bool<br>
><br>
><br>
> I would consider this as a quite nice solution.<br>
><br>
><br>
> Greetings,<br>
> Daniel<br>
> _______________________________________________<br>
> Beginners mailing list<br>
> <a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
> <a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</div></div></blockquote></div><br></div>