Skip to content

Instantly share code, notes, and snippets.

View raboof's full-sized avatar

Arnout Engelen raboof

View GitHub Profile
@raboof
raboof / mapValue
Created April 24, 2015 11:59
mapValue
implicit class PimpMyMap[A,B](map: Map[A,B]) {
def mapValue(a: A, f: B =>B) = map.map {
case (`a`, b) => (a, f(b))
case other => other
}
}
import akka.actor.ActorPath
trait AtLeastOnceTransmission[A] extends akka.persistence.AtLeastOnceDelivery {
private var unconfirmed = Map[A, Set[Long]]()
def transmit(destination: ActorPath, transmissionId: A, message: Any): Unit = {
deliver(destination, { deliveryId ⇒
unconfirmed = add(unconfirmed, transmissionId, deliveryId)
message
})
@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
}
)
@raboof
raboof / keybase.md
Created August 12, 2014 05:40
Keybase proof

Keybase proof

I hereby claim:

  • I am raboof on github.
  • I am raboof (https://keybase.io/raboof) on keybase.
  • I have a public key whose fingerprint is B354 2F13 5550 0168 DD4F F2FA 1431 BC1D 5327 EB56

To claim this, I am signing this object: