Skip to content
This repository has been archived by the owner on Jun 6, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1 from guardian/rk-flatmap
Browse files Browse the repository at this point in the history
Add Box.flatMap
  • Loading branch information
Regis Kuckaertz committed Sep 7, 2017
2 parents 09b20e2 + 7d5aa6c commit 6e10fe8
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/scala/com/gu/Box.scala
Expand Up @@ -15,6 +15,7 @@ abstract class Box[T] {
def alter(f: T => T): Future[T]

def map[A](f: T => A): Box[A]
def flatMap[A](f: T => Box[A]): Box[A]
}

object Box {
Expand All @@ -34,5 +35,6 @@ private class AtomicRefBox[T](t: T) extends Box[T] {
def alter(f: T => T): Future[T] = Future.successful(ref.updateAndGet(t => f(t)))

def map[A](f: T => A): Box[A] = new AtomicRefBox[A](f(get()))
def flatMap[A](f: T => Box[A]): Box[A] = f(get())
}

0 comments on commit 6e10fe8

Please sign in to comment.