DEV Community

Discussion on: What is your favourite ES6 feature?

Collapse
 
pengeszikra profile image
Peter Vivo • Edited

generator function you can get in and leave (yield) so many times, it is perfect for declarative coding time consuming process. Modern usecase is redux-saga

really old poker example on codepen.io

   // example of use generators
   * singleRound(){

    for( let deal of this.dealing() ) yield deal

    for( let flop of this.theBetRound( 'Flop' ) ) yield flop

    for( let flop of this.theFlop() ) yield

    for( let turn of this.theBetRound( 'Turn' ) ) yield turn
    yield this.theTurn(); 

    for( let river of this.theBetRound( 'River' ) ) yield river
    yield this.theRiver(); 

    for( let showdown of this.theBetRound( 'Showdown' ) ) yield showdown

    let winnerIs = []
    for( let score of this.showScores( winnerIs )) yield score
    let winner = this.theShowdown( winnerIs )
    yield winner    
    winner.chips += this.dealer.drawBet()
    for( let pause of Array(10)) yield winner

    // yield this.theShowdown()
  }
Enter fullscreen mode Exit fullscreen mode
Collapse
 
justtanwa profile image
Tanwa Sripan

Really cool, thank you for sharing!