Skip to content

Instantly share code, notes, and snippets.

@lbialy
lbialy / conway.scala
Last active August 2, 2016 06:33
Conway's Game of Life in functional Scala with lazy eval
type Position = (Int, Int)
type State = Set[Position]
def gameOfLife(state: State): Stream[State] =
if (state.isEmpty) Stream.empty
else state #:: gameOfLife(nextFrom(state))
def nextFrom(state: State) = {
for {
field <- getFieldsFromState(state)