[Haskell-cafe] Append after index and update items after inserted item with lens
Li-yao Xia
lysxia at gmail.com
Tue Mar 13 10:48:09 UTC 2018
The only item of index satisfying (> 2) in the list things is (A 3).
Li-yao
On 03/13/2018 02:44 AM, Cody Goodman wrote:
> Hello,
>
> I'm trying to insert a new elemnt into a list after a given index and
> increment the orderId accordingly with the lens library.
>
> I'm a bit confused at why this code isn't working:
>
> ```
> import Control.Lens
>
> data A = A { _customOrderId :: Int } deriving Show
>
> things = [ A {_customOrderId = 0}
> , A {_customOrderId = 1}
> , A {_customOrderId = 2}
> , A {_customOrderId = 3}
> ]
>
> main = print $ things & ( (_drop 2 %~ ((A 22)<|)) . ((traversed .
> indices (> 2) . customerOrderIdLens) %~ (+ 1)) )
> ```
> The first portion works to insert where desired, but the second portion
> `((traversed . indices (> 2) . customerOrderIdLens) %~ (+ 1))` only
> increments the order id in indices 4.
>
> Any idea why this is happening?
>
> Thanks,
>
> Cody Goodman
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
>
More information about the Haskell-Cafe
mailing list