Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Pac-Man multiplayer server - Scala & basic FP

Project is a playground for playing with simple functional programming tools in Scala to build services that are easily testable.

Testing manually using cURL

> curl -H "Content-Type: application/json" -v http://localhost:8080/backend/games -d '{ "gridName": "small" }'
> curl http://localhost:8080/backend/games/1
> curl http://localhost:8080/backend/games/1
> curl http://localhost:8080/backend/games/1
> curl -XPUT -H "Content-Type: application/json" http://localhost:8080/games/1/direction -d '{ "newDirection": "south" }'
> curl http://localhost:8080/backend/games/1

Workshop: TDDing Functional Web Apps

Get some theoretical and practical overview of the TDD approach & Functional Programming by creating a multiplayer Pac-Man game server.

  • First steps in Scala and Scalatest.
  • Test Driven Development (baby steps, starting with the game logic and moving towards HTTP).
  • Purely functional approach (separated data and behaviors, no exceptions, ADTs, Options).
  • Modeling using immutable structures.
  • Separating the concerns by using functions as input parameters.
  • Creating loosely coupled modules by using type parameters.
  • Using function composition to connect all the dots.
  • Using optics to deal with immutable changing data.


Workshop plan

Part I: Immutability (warm-up)

  • theory
    • using immutable structures
    • bags of functions
  • practice - GameEngine
    • review GameState and how GameEngine contains functions that get and return GameState
    • TODO: make "(not) start the game with specified grid" tests green

Part II: Introduction to stateless tests & TDD using Scalatest

  • theory
    • difference between tests and TDD tests
    • using traits to easily isolate test environments
  • practice - GameEngineTest
    • review already implemented tests
    • review implementation: how movePacMan evolved into "not move Pac-Man into a wall" test
    • TODO: implement "wrap Pac-Man around the grid (horizontally/vertically)" failing tests and make them green
    • TODO (optional): implement brand new "move Pac-Man in the desired direction after wall ends" failing test and make it green
    • all GameEngineTest tests should be green

Part III: Separating the concerns using functions

  • theory
    • how to properly unit test the HTTP layer?
    • review entangled.StatefulHttpRoutes - hard to test means entangled concerns
    • using functions as parameters
    • abstracting over state using type parameters
  • practice - HttpRoutesTest
    • live coding "(not) allow creating a new game in chosen grid configuration" test and implementation (using GameState first)
    • TODO: implement "(not) allow getting Pac-Man's state in an (unknown) existing game" failing tests and make them green
    • TODO (optional): think how would you approach using newly created HttpRoutes functions in production server
  • reading:

Part IV: Connecting all dots

  • theory
    • integration tests without running a server?
  • practice
    • TODO: make StatefulHttpRouteTest green

Talk: Building testable APIs with functions and meshes

Slides are available on speakerdeck.


Backend for multiplayer Pac-Man games using basic FP techniques in Scala.







No packages published