andrewducker: (obey the penguin)
[personal profile] andrewducker
Having finally gotten back to the stuff I was looking at a couple of weeks ago, I've now discovered that I can replace:
doggies.ForEach(
    dog => dog.Paws.ForEach(
        paw => paw.Claws.ForEach(
            claw => claw.Clip())));

with
var myClaws = from dog in doggies from paw in dog.Paws from claw in paw.Claws select claw;
foreach (Claw claw in myClaws)
{
    claw.Clip();
}

Sadly, LINQ doesn't seem to have any way of executing queries rather than returning result sets. But then it is Language INtegrate Query. I think that's about as simple as you can get. Although I could replace the foreach loop with
myClaws.ForEach(claw => claw.Clip());
if I really wanted to...

Date: 2008-04-20 10:06 pm (UTC)
From: [identity profile] figg.livejournal.com
Can you do

(from dog in doggies from paw in dog.Paws from claw in paw.Claws select claw).ForEach(claw => claw.Clip());

?

Date: 2008-04-21 11:43 am (UTC)
From: [identity profile] figg.livejournal.com
p.s. maybe you should stick a clipAllClaws() method in Dog such that it contains the inner for each loops. hurr hurr

Date: 2008-04-20 10:21 pm (UTC)
From: [identity profile] surliminal.livejournal.com
you'd have loved the doggies at the pub today:)

Date: 2008-04-21 12:37 am (UTC)
darkoshi: (Default)
From: [personal profile] darkoshi
It sounded like your original intent was to make the code more easily understandable, but you appear to be going the other way now, from my perspective.

Date: 2008-04-21 11:47 am (UTC)
From: [identity profile] figg.livejournal.com
His original intent was to replace an older iteration idiom (for(i=o,i++;i<lim){...}) with a newer one (foreach (i in collection) {...}). (Because he liked the newer style, and disliked the older one) Since the original was just as readable and understandable before :D

Date: 2008-04-21 01:17 am (UTC)
From: [identity profile] holyoutlaw.livejournal.com
Dog dog doggity dog paw paw clippity clip clip clip Next!

Date: 2008-04-21 08:33 am (UTC)
From: [identity profile] robhu.livejournal.com
Come on, I thought the standard Hello World! for LINQ was the one line / one query ray tracer.

Date: 2008-04-21 09:11 am (UTC)
From: [identity profile] robhu.livejournal.com
Well, now it doesn't seem very impressive.

March 2026

S M T W T F S
1 2 3 4 56 7
8 9 1011121314
15161718192021
22232425262728
293031    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Mar. 10th, 2026 01:05 pm
Powered by Dreamwidth Studios