Automatically perform shallow merges on case classes. Treat your data with the latest updates!
Branch: develop
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
project
src
.gitignore
.travis.yml
LICENSE
README.md
build.sbt
bulletin.sublime-project

README.md

Bulletin

A library for automatically performing shallow merges on case classes. Treat your data structures to the latest updates!

Copyright 2016 Dave Gurnell. Licensed Apache 2.

Build Status Coverage status Maven Central

Getting Started

Grab the code by adding the following to your build.sbt:

libraryDependencies += "com.davegurnell" %% "bulletin" % "<<VERSION>>"

Create two case classes representing a data structure and an update:

case class Person(
  id: Long,
  name: String,
  email: Option[String])

case class Update(
  name: Option[String],
  email: Option[Option[String]])

Create instances of those classes:

val person = Person(123L, "Bruce Wayne", Some("bruce@waynemanor.com"))
val update = Update(Some("Batman"), Some(None))

And merge them!

import bulletin._

val updated = person merge update
// updated: Person = Person(123L, "Batman", None)

No update function is required.

Bulletin matches fields in Update to fields in Person by name and type.

If a field in the update has the same type as a field in the original, it always overwrites the original.

If a field in the update is an Option of a field in the original, it overwrites the original iff it is set to Some.

If you try to merge a data structure that doesn't conform to the correct patterns, you'll get a compile error:

person merge "This isn't an update!"
// compile error:
//   Cannot update a Person with a String.
//   Check the field types match up,
//   or manually create a Merge instance for these types.