Skip to content

An implementation of Conway's Game of Life using functional concepts in Swift

Notifications You must be signed in to change notification settings

ColinEberhardt/SwiftFunctionalLife

Repository files navigation

This project demonstrates an implementation of Conway's Game of Life using functional concepts.

You can read much more about this project in the accompanying blog post.

For a quick taster, the following snippet shows how the rules of Life are implemented within this code:

// rules of life
let liveCells = cells.filter { $0.state == .Alive }
let deadCells = cells.filter { $0.state != .Alive }

let dyingCells = liveCells.filter { livingNeighboursForCell($0) !~= 2...3 }
let newLife =  deadCells.filter { livingNeighboursForCell($0) == 3 }

// updating the world state
newLife.each { (cell: Cell) in cell.state = .Alive }
dyingCells.each { (cell: Cell) in cell.state = .Dead }

About

An implementation of Conway's Game of Life using functional concepts in Swift

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages