Skip to content

Instantly share code, notes, and snippets.

@erica
Created June 23, 2014 16:58
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 erica/481a34bc2a6f838dcdbe to your computer and use it in GitHub Desktop.
Save erica/481a34bc2a6f838dcdbe to your computer and use it in GitHub Desktop.
Xcode seems to hate this
import Foundation
struct BagGenerator<T:Hashable> : Generator
{
typealias Element = (T, Int, Int)
var count = 0
var _backingGenerator : DictionaryGenerator<T, Int>
init(_ backingDictionary : Dictionary<T, Int>) {
_backingGenerator = backingDictionary.generate()
}
func next() -> (T, Int, Int)?
{
var pair : (T, Int)? = _backingGenerator.next()
if (!pair) {return nil}
var tuple = (count, pair!.0, pair!.1)
count = count + 1
return tuple
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment