Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Volte
Oct 4, 2004

woosh woosh
I'm not even sure in what kind of nightmare land you'd want iterating over the same collection twice in a row to print two different results. IEnumerator is the iterator for IEnumerable. Iterators are mutable even when the enumerable isn't, which is why it makes no sense to expect any sort of consumer state to be encoded in the enumerable. foreach creates a new iterator (IEnumerator). If you want to use the same enumerator across multiple loops (i.e. for chunking), create it yourself before the loops and use the MoveNext method manually.

edit: also for LINQ it wouldn't be that hard to write a collection wrapper that does chunking for you implementing IEnumerable.

Volte fucked around with this message at 14:20 on Jun 22, 2014

Adbot
ADBOT LOVES YOU

Volte
Oct 4, 2004

woosh woosh

Malcolm XML posted:

The factory-ness of ienumerable is fine, it's just that it doesn't make a lot of sense to iterate over a factory.
I don't see why. An object is enumerable if and only if it is a factory which can create an enumerator for itself, so by that definition it only makes sense to iterate over a factory. It makes even less sense to iterate over an iterator in my opinion.

It's such an unusual situation to have to reuse an iterator over multiple loops that I don't see why just converting your foreach loops into regular for or while loops using explicit iterators is such a big deal.

Also,
C# code:
public class IteratorView<T> : IEnumerable<T> {
    private readonly IEnumerator<T> enumerator;

    private IteratorView(IEnumerator<T> enumerator) {
        this.enumerator = enumerator;
    }
 
    public static IteratorView<T> FromEnumerable(IEnumerable<T> enumerable) {
        return new IteratorView<T>(enumerable.GetEnumerator());
    }

    public static IteratorView<T> FromEnumerator(IEnumerator<T> enumerator) {
        return new IteratorView<T>(enumerator);
    }

    public IEnumerator<T> GetEnumerator() {
        return this.enumerator;
    }

    IEnumerator IEnumerable.GetEnumerator() {
        return this.enumerator;
    }
}
C# code:
var x = IteratorView<int>.FromEnumerable(Enumerable.Range(1,10));

foreach (int i in x.Take(5)) { Console.WriteLine(i); }
foreach (int i in x.Take(5)) { Console.WriteLine(i); }

// Prints 1 through 10

Volte
Oct 4, 2004

woosh woosh

crashdome posted:

Anyone use Xamarin? Client is looking to get a native framework supplied both for iOS and Android development into an app for both platforms and setting up two development environments for the same project seems cumbersome.
I'm using it for exactly that and it's basically the best thing ever, as long as you can afford the price tag (or can get the student discount). Definitely look at MvvmCross, and avoid Xamarin.Forms since it is still basically alpha-quality software despite the production status.

Volte
Oct 4, 2004

woosh woosh

crashdome posted:

Good to hear. Think I could get away with the free IDE for a demo? I'm sure if the demo was successful, the $999/year would be a drop in the bucket for the planned product development.
I don't really know how the free tier scales, since I think it has size limitations (i.e. it will fail if the compiled binary is too big), but it's worth checking out at least. There is a 30-day trial of the business version though if you think you could get the demo done in that length of time, but the compiled apps only run for 24 hours.

Volte
Oct 4, 2004

woosh woosh

crashdome posted:

I think that's possible. It looks amazing! Definately disappointed by the limitations of the free version but, the trial should be sufficient. I'll definitely make use of the 30 days for sure. Just realized it's $999 PER platform. Ugh.
There is strong reason to believe that Xamarin will be part of Visual Studio in the not too distant future, so there's still hope.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply