Skip to content

Instantly share code, notes, and snippets.

@stanch
Created February 23, 2016 00:56
Show Gist options
  • Save stanch/f5aa9223d47ac7577958 to your computer and use it in GitHub Desktop.
Save stanch/f5aa9223d47ac7577958 to your computer and use it in GitHub Desktop.
case class persistence visualized
case class Street(name: String, house: Int)
case class Address(street: Street, city: String)
case class Person(address: Address, age: Int)
val person1 = Person(Address(Street("Functional Rd.", 1), "London"), 35)
val person2 = person.modify(_.address.street.house).using(_ + 3)
/*
┌───────────┐ ┌───────────┐
│Person (35)│ │Person (35)│
└──────┬────┘ └──────┬────┘
│ │
v v
┌──────────┐ ┌──────────┐
│Address ()│ │Address ()│
└──┬────┬──┘ └───┬───┬──┘
│ │ │ │
│ └───┐ │ └─────┐
v │ v │
┌──────────┐ │ ┌──────────┐ │
│Street (1)│ │ │Street (4)│ │
└─────┬────┘ │ └─────┬────┘ │
│ │ │ │
│ └─────────┼────┐ │
│ ┌──────────┘ │ │
│ │ │ │
v v v v
┌───────────────────────┐ ┌───────────────┐
│String (Functional Rd.)│ │String (London)│
└───────────────────────┘ └───────────────┘
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment