import { assertExists } from '@ulangi/assert' ; import { Vocabulary } from '@ulangi/ulangi-common/interfaces' ; import { shuffleImmutableMap } from '@ulangi/ulangi-common/utils' ; import { OrderedMap } from 'immutable' ; export class RandomVocabularyIterator < V extends Vocabulary = Vocabulary > { private vocabularyQueue : OrderedMap < string , V > ; private currentVocabulary ? : V ; public constructor ( vocabularyList ? ) { this . vocabularyQueue = OrderedMap ( vocabularyList || [ ] ) ; } public next ( ) { this . currentVocabulary = assertExists ( this . vocabularyQueue . first ( ) , 'nextVocabulary should not be null or undefined' ) ; this . vocabularyQueue = this . vocabularyQueue . rest ( ) ; return this . currentVocabulary ; } public current ( ) { return assertExists ( this . currentVocabulary , 'currentVocabulary should not be null or undefined' ) ; } public isDone ( ) { return this . vocabularyQueue . isEmpty ( ) ; } public getQueueSize ( ) { return this . vocabularyQueue . size ; } public merge ( vocabularyList ) { this . vocabularyQueue = this . vocabularyQueue . merge ( vocabularyList ) ; } public shuffleQueue ( ) { this . vocabularyQueue = shuffleImmutableMap ( this . vocabularyQueue ) ; } }