Skip to content

Instantly share code, notes, and snippets.

@mcsee
Last active August 26, 2023 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcsee/0358951abbf771f2b63a3ae6833ea210 to your computer and use it in GitHub Desktop.
Save mcsee/0358951abbf771f2b63a3ae6833ea210 to your computer and use it in GitHub Desktop.
public interface Iterator {
public bool HasNext { get; set;}
public object Next();
}
public Iterator Reverse(Iterator iterator) {
var list = new List<int>();
while (iterator.HasNext) {
list.Insert(0, iterator.Next());
}
return new ListIterator(list);
}
public class MyCollection implements Iterator {
public bool HasNext { get; set;} // Implementation details
public object Next(); // Implementation details
}
public class myDomainObject sum(Iterator anObjectThatCanBeIterated) {
// Loose coupling
}
// Can use any Iterator
// (even a mocked one as long as it adheres to the protocol)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment