39 votes
Accepted

Count all vowels in string

An alternative route is to use string.replace() and Regular Expressions to strip everything but the vowels from the string. Then count the length of the resulting ...
user avatar
  • 24.8k
36 votes
Accepted

Simple Example of an Iterable and an Iterator in Java

Variables I understand why you have the Range.this.end and Range.this.start to avoid confusion about where those variables come ...
user avatar
  • 96.7k
32 votes

Extension method replacing elements from an IEnumerable<T> collection

Why didn't Microsoft include this in the .NET framework? Probably because it can be realized in one line with Select: ...
user avatar
  • 8,498
30 votes
Accepted

Custom iterator for a linked list class

Your iterator is missing a few important details: You should provide the pre- and post-increment operators (++it and it++). ...
user avatar
  • 17k
29 votes
Accepted

StreamIterable - create an iterable from a Java 8 Stream

Two things: I think you have missed the native implementation. Are you intentionally re-inventing the wheel? Streams have an iterator() method. Note that streams cannot be reversed, so, while you can ...
user avatar
  • 96.7k
28 votes

Count all vowels in string

I'm just wondering if there's an easier way to solve this problem without the big blocky code in the if statement. Well, you could put all of those in an array: <...
user avatar
27 votes
Accepted

Method returning IEnumerable<T> should ToList() or not

Does code that calls the method always expect List functionality (access by index, etc.)? Return a List. Does code that calls ...
user avatar
  • 1,873
25 votes

Pythonish integer range in Java

If you're targeting Java 8, then you should make an IntStream and a PrimitiveIterator.OfInt instead. You can do more ...
user avatar
25 votes
Accepted

Extension method replacing elements from an IEnumerable<T> collection

I cannot comment about the speed because I didn't benchmark it but there are two obvious improvements. add an IEqualityComparer<T> as a third parameter so ...
user avatar
  • 43.8k
20 votes

StreamIterable - create an iterable from a Java 8 Stream

You should not need a special class for this. Method references can be cast to functional interfaces. In this particular case, however, remember that the stream returned by ...
user avatar
18 votes
Accepted

Determine added, removed and kept items between two lists

First, let's look at the naive implementation using sets: ...
user avatar
  • 40.5k
17 votes
Accepted

Zipping two lists with an offset in Python

You're on the right track, but it can be simplified to the following. Note also that the step variable name could add confusion because Python ranges and slices ...
user avatar
  • 9,475
15 votes

Method returning IEnumerable<T> should ToList() or not

I think the real question here is can the return value be lazily evaluated? This is essentially what this comes down to. IEnumerable is lazily evaluated in that ...
user avatar
  • 3,753
15 votes

Flags on steroids

I'm not going to say I'd use this, nor that I wouldn't. I think it's a clever1 use of generics, and turns C# enums into something else that could possibly be called ...
user avatar
15 votes
Accepted

Merge n sorted iterators

There are no docstrings. What do these functions do? What arguments do they take? What do they return? Decorators are normally named after the effect they have on the decorated function. For example <...
user avatar
  • 49.1k
15 votes

Counting elements meeting a predicate in an enumerable without iterating the entire sequence

You can use the Linq Take to accomplish the same thing ...
user avatar
  • 4,064
15 votes
Accepted

Basic iterator supporting vector implementation

The range-based for loop This works via the begin() and end() functions. So for any class <...
user avatar
  • 91.5k
14 votes

"Zip-like" functionality with C++11's range-based for-loop

There are a few serious things that haven't been brought up by the other two answers yet. Dereferencing issues Let's say I am zipping a vector<T> and a <...
user avatar
  • 18.3k
14 votes

Custom iterator for a linked list class

The requirements for a forward iterator are: Forward Iterator It is a refinement of: Input Iterator Output Iterator Trivial Iterator Equity Comparable Default Constructable Assignable If you read ...
user avatar
  • 91.5k
14 votes
Accepted

Pythonish integer range in Java

Minor point. The step is zero is an odd error message. Wouldn't it be better to actual explain the problem, ie. The step cannot be zero The user (hopefully) knows what paramaters they've ...
user avatar
13 votes

Simple Example of an Iterable and an Iterator in Java

Overall, it's pretty good code to learn from. Functionality I like that you've used the inclusive-exclusive convention for the lower and upper bounds, respectively. The rationale for that design ...
user avatar
13 votes
Accepted

StackList<T> implementation

Issues public void Push(T item) { _stackList.Insert(0, item); } The hurts the stack list. It would be much easier if you just added new items at the end of ...
user avatar
  • 43.8k
13 votes
Accepted

Sorting algorithm, possibly a new one

Algorithm What you have implemented is called (linear) insertion sort. It is very old, sorry your method is not new or novel ;) It has average case O(n^2) time complexity which is basically unusable ...
user avatar
  • 16.4k
13 votes
Accepted

Input Iterator implementation

Input iterator is an abstract concept I think you are very confused. “Input iterator” is a concept. A concept is an abstract specification, not a concrete “thing”. You can’t make an “implementation of ...
user avatar
  • 8,116
12 votes

Streaming int support

After reading the problem description and before reading your code, I implemented something that was very similar to what you already have, which means that your approach to the problem is perfectly ...
user avatar
12 votes
Accepted

random_iterator in C++

Naming First of, what you have created is not an iterator so naming it as such is misleading. I would recommend a name but I actually think that you should redesign your class and the name I would ...
user avatar
  • 16.4k
12 votes
Accepted

Counting elements meeting a predicate in an enumerable without iterating the entire sequence

There are so many different solutions already that I won't post another. But there is something else that bothers me, the names of the extensions. I find they are too confusing. Expecially ...
user avatar
  • 43.8k
12 votes

Basic iterator supporting vector implementation

Use delete[] You are allocating an array of objects with new[], but attempting to delete them with ...
user avatar
  • 857
12 votes
Accepted

Decoding assembly instructions in a Game Boy disassembler

I have some ideas about how you might be able to improve your program. Avoid problems Rather than trying to deal with the problem for every instruction, one approach is avoiding it entirely. One ...
user avatar
  • 64.1k
12 votes

Zipping two lists with an offset in Python

Using itertools.tee to zip an iterable with itself Since you are iterating twice on the same iterable, one possibility is to use ...
user avatar
  • 221

Only top scored, non community-wiki answers of a minimum length are eligible