Created
May 28, 2022 17:19
-
-
Save nanjizal/c3beb378a1cc89c2754cfceecbfbef24 to your computer and use it in GitHub Desktop.
Backwards Iterator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@:access(IntIterator.min, IntIterator.max ) | |
class IntIterStart { | |
public var start: Int; | |
public var max: Int; | |
public function new( min_: Int, max_: Int ){ | |
start = min_; | |
max = max_; | |
} | |
} | |
@:transitive | |
@:access( IntIterator.min, IntIterator.max ) | |
abstract Backwards( IntIterStart ) from IntIterStart { | |
public inline | |
function new( min: Int, max: Int ){ | |
this = new IntIterStart( min, max ); | |
} | |
@:from | |
static inline | |
public function fromIterator( ii: IntIterator ): Backwards { | |
return new Backwards( ii.min, ii.max ); | |
} | |
@:to | |
function toIterStart():Backwards { | |
return new Backwards( this.start, this.max ); | |
} | |
public inline function hasNext() { | |
return this.max > this.start; | |
} | |
public inline function next() { | |
return ( this.max-- -1 ); | |
} | |
} | |
class Test { | |
static function main() { | |
for( i in (( 0...10 ): Backwards ) ){ | |
trace( i ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment