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 :-
Any suggestions ?
Cheers,
Phil.
using the Extended Method 'Union' ... help ?
- Phil Hepburn
- Posts: 743
- Joined: Sun Sep 11, 2016 2:16 pm
using the Extended Method 'Union' ... help ?
- Attachments
-
- NickF_Qs_02.jpg (52.07 KiB) Viewed 592 times
- Phil Hepburn
- Posts: 743
- Joined: Sun Sep 11, 2016 2:16 pm
using the Extended Method 'Union' ... help ?
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.
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.
-
- Posts: 248
- Joined: Fri Oct 14, 2016 7:09 am
using the Extended Method 'Union' ... help ?
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.
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
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)
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
- Phil Hepburn
- Posts: 743
- Joined: Sun Sep 11, 2016 2:16 pm
using the Extended Method 'Union' ... help ?
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 :-
and some that appears to work :-
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.
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 :-
and some that appears to work :-
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.
- Phil Hepburn
- Posts: 743
- Joined: Sun Sep 11, 2016 2:16 pm
using the Extended Method 'Union' ... help ?
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.
Good Luck,
Phil.
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.
Good Luck,
Phil.
- Phil Hepburn
- Posts: 743
- Joined: Sun Sep 11, 2016 2:16 pm
using the Extended Method 'Union' ... help ?
Robert,
I have a one-liner, albeit not a chained syntax this seems to work in X# :-
I will now go to C# and try stuff there.
Cheers,
Phil.
I have a one-liner, albeit not a chained syntax this seems to work in X# :-
I will now go to C# and try stuff there.
Cheers,
Phil.
- Phil Hepburn
- Posts: 743
- Joined: Sun Sep 11, 2016 2:16 pm
using the Extended Method 'Union' ... help ?
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 :-
I hope this proves useful and helpful to you.
Cheers,
Phil.
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 :-
I hope this proves useful and helpful to you.
Cheers,
Phil.
using the Extended Method 'Union' ... help ?
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
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
XSharp Development Team
chris(at)xsharp.eu
- Phil Hepburn
- Posts: 743
- Joined: Sun Sep 11, 2016 2:16 pm
using the Extended Method 'Union' ... help ?
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 :-
Best regards to one and all,
Phil.
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 :-
Best regards to one and all,
Phil.
- Attachments
-
- ChrisUnion_32.jpg (99.92 KiB) Viewed 592 times
- Phil Hepburn
- Posts: 743
- Joined: Sun Sep 11, 2016 2:16 pm
using the Extended Method 'Union' ... help ?
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.
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.