All Projects → ColinEberhardt → SwiftFunctionalLife

ColinEberhardt / SwiftFunctionalLife

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

Programming Languages

swift
15916 projects

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 }
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].