dart - How to implement Iterable<E> -
i trying port java code below dart , puzzled this.
in java iterable interface clean 1 method , implement snap.
how code best transformed dart?
/** * chess squares represented bitmap. */ public class chesssquares implements iterable<chesssquare> { private static class chesssquaresiterator implements iterator<chesssquare> { long bits; int nextbit; public chesssquaresiterator(long bits) { this.bits = bits; nextbit = long.numberoftrailingzeros(bits); } @override public boolean hasnext() { return (nextbit < 64); } @override public chesssquare next() { chesssquare sq = chesssquare.values()[nextbit]; bits = bits & ~sq.bit; nextbit = long.numberoftrailingzeros(bits); return sq; } @override public void remove() { throw new unsupportedoperationexception(); } } @override public iterator<chesssquare> iterator() { return new chesssquaresiterator(bits); } ...
by using iterablemixin
need implement iterator
-function.
class chesssquares extends object iterablemixin<chesssquare> { iterator<chesssquare> iterator() => new chesssquaresiterator(bits); ... }
visit http://blog.sethladd.com/2013/03/first-look-at-dart-mixins.html short introduction on mixins.
the iterator
-interface straight forward. have implement function movenext
, getter current
.
Comments
Post a Comment