using the Extended Method 'Union' ... help ?

This forum is meant for anything you would like to share with other visitors
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

using the Extended Method 'Union' ... help ?

Post by Phil Hepburn »

Hi Guys,

This question may be best aimed at Nick as he has the most experience of extended methods and their use.

I am after a way to place together all three of the small sets in the SubX lists shown in the attached image. I need a larger final set which includes all item entries.

I thought it would be easy to chain the EMs for Union, but for some reason I have hit some issues and snags.

Here is what I got to work but I feel there should be another way :-
NickF_Qs_01.jpg
NickF_Qs_01.jpg (79.78 KiB) Viewed 621 times
Any suggestions ?

Cheers,
Phil.
Attachments
NickF_Qs_02.jpg
NickF_Qs_02.jpg (52.07 KiB) Viewed 621 times
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

using the Extended Method 'Union' ... help ?

Post by Phil Hepburn »

whoops,

images the wrong way around - '_02' should be the working one and '_01' the image where I show what I tried and failed with ............

tricky this stuff - or is it just me today ?

Phil.
NickFriend
Posts: 248
Joined: Fri Oct 14, 2016 7:09 am

using the Extended Method 'Union' ... help ?

Post by NickFriend »

Hi Phil,

I haven't really used Union, but the logic of Linq (that the output from one method in the chain is the input to the next) means that this ought to work.

Code: Select all

nListSubAll := nListSub1.Union(nListSub2).Union(nListSub3)
Just a thought, but I wonder if local implied means the compiler has trouble with the output... maybe try typing each variable as local List<int> to see what happens.

You could also try Concat() to see if that worked better - clutching at straws!

Or just use AddRange()... probably makes more sense in this context.

Nick
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

using the Extended Method 'Union' ... help ?

Post by Phil Hepburn »

Hi Nick,

Thanks .... but lets forget the clutching at straws approach for now. Union is a great approach and I have used it in SQL to good effect in the past.

Yes, this is just as I thought - output from one EM as input to another - but my first two best shots seemed to fail ;-0((

I will give it another go before I jump to ask Robert if something is amiss.

ROBERT - Help Please !!! ???

I feel that there is something wrong with using Union and only when in a chain.

here is some code to go on :-
RobertUnion_01.jpg
RobertUnion_01.jpg (92.66 KiB) Viewed 621 times
and some that appears to work :-
RobertUnion_02.jpg
RobertUnion_02.jpg (94.86 KiB) Viewed 621 times
Although I can't show it I have tried all sort of permutations with code snippets and only find the one way works, and that is to split a line.

Can you please enlighten me and possibly others,
Phil.
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

using the Extended Method 'Union' ... help ?

Post by Phil Hepburn »

Oh! - Robert,

You may also be interested in this approach - see image - BUT - it is not chaining EMs which is really what this issue is all about.

I will go and try C# to see what happens there.
RobertUnion_11.jpg
RobertUnion_11.jpg (91.43 KiB) Viewed 621 times
Good Luck,
Phil.
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

using the Extended Method 'Union' ... help ?

Post by Phil Hepburn »

Robert,

I have a one-liner, albeit not a chained syntax this seems to work in X# :-
RobertUnion_21.jpg
RobertUnion_21.jpg (67.72 KiB) Viewed 621 times
I will now go to C# and try stuff there.

Cheers,
Phil.
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

using the Extended Method 'Union' ... help ?

Post by Phil Hepburn »

Hi again Robert,

According to my recent little trip / foray into C# it would appear that the X# compiler may not be handling chained EMs (extension methods) correctly.

Here is what I did in C# to test :-
RobertUnion_31.jpg
RobertUnion_31.jpg (26.98 KiB) Viewed 621 times
I hope this proves useful and helpful to you.

Cheers,
Phil.
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

using the Extended Method 'Union' ... help ?

Post by Chris »

Hi Phil,

UNION is a keyword in x#, so you need to prefix it with @@ (as in @@Union()). This way it should work the same as in c#.

Chris
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

using the Extended Method 'Union' ... help ?

Post by Phil Hepburn »

Thanks a bunch Chris,

A simple solution to what felt at this end like a nasty problem ;-0) Well done !

I have now got it all working in a similar simple manner to C#.

X# is really starting to feel very good to me and my coding. Still a lot to learn however, but then learning is fun, even when you are old and past it !!!

Here is my positive proof :-
ChrisUnion_31.jpg
ChrisUnion_31.jpg (100.92 KiB) Viewed 621 times
ChrisUnion_32.jpg
ChrisUnion_32.jpg (99.92 KiB) Viewed 621 times
Best regards to one and all,
Phil.
Attachments
ChrisUnion_32.jpg
ChrisUnion_32.jpg (99.92 KiB) Viewed 621 times
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

using the Extended Method 'Union' ... help ?

Post by Phil Hepburn »

Chris,

You had better remind me as to where to go to get a full list of the current KEYWORDS in X#.

I am sure I have seen something relating to a list but can't remember.

Thanks again,
Phil.
Post Reply