Coder Social home page Coder Social logo

Comments (8)

GoogleCodeExporter avatar GoogleCodeExporter commented on August 16, 2024
I like the idea of a Generate method (and I've written one before) but I don't 
think 
I'd specify either a condition or a number of elements to generate - using Take 
and 
TakeWhile do that well enough, I think.

I haven't looked at the patch yet - will try to do so tonight.

Original comment by jonathan.skeet on 16 Feb 2009 at 7:34

from morelinq.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 16, 2024
We can borrow from Python's (x)range here and add a Range operator:

Range(int stop)
Range(int start, int stop)
Range(int start, int stop, int step)

I can also imagine a default, zero-arguments, overload of Range that produces 
the 
full series of integers/longs. With this in place, one can use Select and other 
existing operators to the same effect. For example:

Series.Expand(2, n => n * n, n > 1000) => (2, 4, 8, 16, 32, 64, 128, 256, 512)

becomes:

Range<int>().Select(n => n + 2)
            .Select(n => n * n)
            .TakeWhile(n => n < 1000)

That can be a bit mouthful and verbose so I can understand CAmmerman's point to 
have 
something that simplifies a very common use case. After all, many base LINQ 
operators also have overloads for projection (see Max, for example) when there 
is 
already Select. However, I would stard with Range because that can serve as a 
basis 
for Expand.

Original comment by azizatif on 16 Feb 2009 at 9:15

from morelinq.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 16, 2024
OK, I'm silly and it had momentarily slipped my mind that Range already exists:
http://msdn.microsoft.com/en-us/library/system.linq.enumerable.range.aspx

So we are now talking about:

Range(2, int.MaxValue).Select(n => n * n).TakeWhile(n => n < 1000)


Original comment by azizatif on 16 Feb 2009 at 9:51

from morelinq.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 16, 2024
> but I don't think I'd specify either a condition or a number of elements to 
generate

I was thinking along the lines of what azizatif was saying, about simplifying 
the
common use cases.  I'm not married to it however.  And we could certainly have 
an
overload without the terminator condition or element count.  On a related note, 
the
terminal check might do better if it worked like TakeWhile, rather than "take 
until".
 The code itself is older, and I don't remember why I chose to do it this way originally.

There might be a better name for this method than Expand, as well.  It was just 
the
simplest thing that applied, in my mind at the time.

Original comment by [email protected] on 16 Feb 2009 at 1:20

from morelinq.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 16, 2024
My example (which has since been repeated by Aziz) was not quite right....  The 
n * n
should be n * 2, to generate the sequence I specified.  n * n would be repeated
squaring, which would overflow quite rapidly. =)

Series.Expand(2, n => n * 2, n > 1000) => (2, 4, 8, 16, 32, 64, 128, 256, 512)

The patch I submitted has the same typo in the comments.

Original comment by [email protected] on 16 Feb 2009 at 3:18

from morelinq.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 16, 2024
If we're looking at Range, I have a much more competent Range class in 
MiscUtil. I'm 
not sure whether I want to bring that over to MoreLinq though - it's useful 
outside 
LINQ too, and I'd rather keep to operators.

@Comment 5: That example still isn't right - it should be:

Series.Expand(2, n => n * 2, n => n > 1000)

which I'd still prefer to see as:

Series.Expand(2, n => n * 2).TakeWhile(n => n <= 1000)

Generating a sequence and terminating it are somewhat orthogonal concepts, and 
the 
latter already exists in a well-known form. I think I'd find the latter easier 
to 
read, aside from anything else.

Original comment by jonathan.skeet on 17 Feb 2009 at 6:31

from morelinq.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 16, 2024
@CAmmerman: You should commit your patch. I agree with Jon, though, to keep the 
terminating condition out for now. It can always be added later in version 2. 
Meanwhile it does not prevent anyone from having their own overload that 
combines 
Expand with TakeWhile or Expand with Take to get your original three-part 
Expand 
version. At least, they'll be getting a tested base to build on.

Original comment by azizatif on 17 Feb 2009 at 11:32

from morelinq.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 16, 2024
Implemented in r38.

Original comment by azizatif on 18 Feb 2009 at 9:31

  • Changed title: Adding series generation/comprehension methods
  • Changed state: Fixed
  • Added labels: Milestone-Release1.0

from morelinq.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.