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 ...
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 ...
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:
...
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++). ...
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 ...
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:
<...
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 ...
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 ...
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 ...
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 ...
18
votes
Accepted
Determine added, removed and kept items between two lists
First, let's look at the naive implementation using sets:
...
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
...
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 ...
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 ...
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 <...
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
...
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 <...
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 <...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
12
votes
Basic iterator supporting vector implementation
Use delete[]
You are allocating an array of objects with new[], but attempting to delete them with ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
iterator × 423c++ × 156
c# × 72
python × 63
java × 62
c++11 × 34
algorithm × 32
performance × 29
python-3.x × 25
javascript × 24
beginner × 23
linked-list × 23
array × 22
c++17 × 22
generator × 22
collections × 17
rust × 16
iteration × 16
reinventing-the-wheel × 15
ecmascript-6 × 15
template × 15
object-oriented × 14
strings × 14
c++14 × 14
tree × 13