Language-ext: Trouble with Lst - SetItem(index, value)

Created on 22 Sep 2017  Â·  11Comments  Â·  Source: louthy/language-ext

Perhaps I'm missing something here but I am trying to update something in a lst at a specified index. It works for index 0 and 1 but after that things get a little strange. Here is a code snippet:

Lst lint = new Lst();
lint = lint.Insert(0, 0).Insert(1, 1).Insert(2, 2);
lint = lint.SetItem(2, 500);

After running this the first item is 500, then 1 then 2 whereas I was expecting 0, 1, 500.
Please advise! Also it only gets worse at higher indexes

bug

Most helpful comment

This is now fixed on v2.1.22. Sorry for the delay!

All 11 comments

Hi Timothy, which version are you running? There was an earlier bug with
Insert that has been fixed. If it's the latest then I'll take a look as
soon as I can.

On Fri, 22 Sep 2017 at 16:51, Timothy Trewartha notifications@github.com
wrote:

Perhaps I'm missing something here but I am trying to update something in
a lst at a specified index. It works for index 0 and 1 but after that
things get a little strange. Here is a code snippet:

Lst lint = new Lst();
lint = lint.Insert(0, 0).Insert(1, 1).Insert(2, 2);
lint = lint.SetItem(2, 500);

After running this the first item is 500, then 1 then 2 whereas I was
expecting 0, 1, 500.
Please advise! Also it only gets worse at higher indexes

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/louthy/language-ext/issues/272, or mute the thread
https://github.com/notifications/unsubscribe-auth/AB5kkxcTPhm3vOiWX_3YSCnaGwIQo9Wmks5sk9dngaJpZM4Pg5bq
.

Hi Paul, thanks for the quick response. This is on the latest stable version from nuget (LanguageExt.Core 2.1.21). Haven't tried building from source or anything like that as of yet. In the example it should have been Lst obviously. I have also tried with other data types with the same result, however.

@timminata Ok, the bug I referred to was a while back, so this is new. I will dig into it. Although probably earliest will be Monday I'm afraid.

@timminata

I just ran this code and it worked. Do you have another example that fails?
```c#
Lst lint = new Lst();
lint = lint.Insert(0, 0).Insert(1, 1).Insert(2, 2);

    Debug.Assert(lint[0] == 0);
    Debug.Assert(lint[1] == 1);
    Debug.Assert(lint[2] == 2);

    lint = lint.SetItem(2, 500);

    Debug.Assert(lint[0] == 0);
    Debug.Assert(lint[1] == 1);
    Debug.Assert(lint[2] == 500);

```

@timminata Never mind, I have just seen it's the enumeration not direct access. Leave it with me.

Yeah that example doesn't work for me, fails on Debug.Assert(lint[0] == 0). Thanks for taking a look

@timminata I've found the issue. It's just mixed up with a few other changes that I need to be a bit careful of. As a temporary fix, avoid SetItem. You can use this below until I can deploy:
c# lint = lint.RemoveAt(2).Insert(2, 500);

Cool, I will use that in the interim. Thanks.

Unfortunately also having problems with that solution. This code fails:

           Lst<int> lint = new Lst<int>();
           lint = lint.Insert(0, 0).Insert(1, 1).Insert(2, 2).Insert(3,3);

            Debug.Assert(lint[0] == 0);
            Debug.Assert(lint[1] == 1);
            Debug.Assert(lint[2] == 2);
            Debug.Assert(lint[3] == 3);

            lint = lint.RemoveAt(2).Insert(2, 500);

            Debug.Assert(lint[0] == 0);
            Debug.Assert(lint[1] == 1);
            Debug.Assert(lint[2] == 500);
            Debug.Assert(lint[3] == 3);

Really strange

This is now fixed on v2.1.22. Sorry for the delay!

Thanks!

Was this page helpful?
0 / 5 - 0 ratings