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
### Keybase proof | |
I hereby claim: | |
* I am sprengerjo on github. | |
* I am sprengerjo (https://keybase.io/sprengerjo) on keybase. | |
* I have a public key ASA1R8bKPafq7TycNTQBmQU9ftqPS4H-R3mJ2g1DovXURwo | |
To claim this, I am signing this object: |
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
package de.sprengerjo.game.xtend; | |
import java.util.ArrayList; | |
import org.eclipse.xtext.xbase.lib.CollectionLiterals; | |
import org.eclipse.xtext.xbase.lib.ExclusiveRange; | |
import org.eclipse.xtext.xbase.lib.Functions.Function0; | |
@SuppressWarnings("all") | |
public class Game { | |
private ArrayList<Integer> _scores = new Function0<ArrayList<Integer>>() { |
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
package de.sprengerjo.game.xtend | |
import static org.junit.Assert.* | |
import org.junit.Test | |
import org.junit.Before | |
class GameTest { | |
var game = new Game() | |
@Before |
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
@Test | |
defvoid gutterGamesOnly() { | |
(1..20).forEach[game.roll(0)] | |
assertEquals(20 * 0, game.score()) | |
} | |
// the implementation so far... | |
class Game { | |
def roll(int score) { |
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
// pretty cool way of saying: sum ‘+’ all values stored in ‘scores’, a is the result of the previous iteration, | |
// b is the current value. | |
[ scores.reduce[a, b | a + b ]] | |
// You can also do something like this: | |
scores.forEach[value, index | println(value + "@" + index)] |