Skip to content

Instantly share code, notes, and snippets.

View raboof's full-sized avatar

Arnout Engelen raboof

View GitHub Profile
@raboof
raboof / FinalVersion.scala
Last active August 29, 2015 14:05 — forked from agemooij/FinalVersion.scala
Functional 'add to basket' experiments
def addItem(newItem: BasketItem): BasketState = {
copy(
items.foldRight((false, List.empty[BasketItem])) {
case (item, (_, out)) if (item.matchesProductAndSizeOf(newItem)) ⇒ (true, item.incrementNumberBy(newItem.numberOfProducts) :: out)
case (item, (didSomethingMatch, out)) ⇒ (didSomethingMatch, item :: out)
} match {
case (false, _) ⇒ newItem :: items
case (true, modifiedItems) ⇒ modifiedItems
}
)
package playground
import scala.concurrent.duration._
import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success, Try}
import akka.actor.{Actor, ActorLogging, ActorRef, Props}
import akka.util.Timeout
import akka.pattern.{ask, pipe}
import playground.Parent.{BulkTasks, Finish, TaskCompleted, TaskFailed}