This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait PersistentEntity[IDType, T <: PersistentEntity[IDType, T]] { | |
type Command | |
type Event | |
type State | |
def id: IDType | |
def state : State | |
def processCommand(command: Command) : List[Event] | |
def processEvent(event: Event) : T |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*\ | |
{\o/} | |
/_\ | |
\*|*/ | |
///|\\\ | |
////|\\\\ | |
/////|\\\\\ | |
object MerryX | |
{def main(santa | |
: Array[String]){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.onCommand[AssignAccountHolderCmd, Done]{ | |
case (AssignAccountHolderCmd(time, accountHolder), ctx, state) => | |
ctx.thenPersist(AssignAccountHolderEvt(time, accountHolder)){ | |
_ => | |
ctx.reply(Done) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Foldable[List].fold(List(1,2,3)) | |
// res1: Int = 6 | |
Foldable[List].fold(List("1","2","3")) | |
// res2: String = "123" | |
// Or you can use the combineAll function | |
List(1,2,3).combineAll | |
// res3: Int = 6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cats.Monoid | |
Monoid[Int].empty |+| 10 | |
// res1: Int = 10 | |
10 |+| Monoid[Int].empty | |
// res2: Int = 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Monoid[A] extends Semigroup[A] { | |
def empty: A | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cats.Foldable | |
// Combining a list with a foldLeft | |
Foldable[List].foldLeft(List(1,2,3), 0){_ |+| _} | |
// res1: Int = 6 | |
// Combining a list of string with a foldLeft | |
Foldable[List].foldLeft(List("1","2","3"), "")(_ |+| _) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cats.Semigroup | |
import cats.implicits._ | |
// Combining strings | |
"Semigroups".combine(" ".combine("combine".combine(" ".combine("things")))) | |
// res1: String = "Semigroups combine things | |
// Which is hard to read so Cats provides convenient infix syntax |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Semigroup[A] { | |
def combine(x: A, y: A): A | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"handle deposit and successful withdrawal" in withTestDriver | |
{ driver => | |
val t1 = Instant.now | |
val t2 = t1.plusSeconds(100) | |
val outcome = driver.run(DepositCmd(t1, "Opening deposit", 100)) | |
outcome.replies should contain only 100 | |
val outcome2 = driver.run(WithdrawCmd(t2, "Transfer to savings", 20)) | |
outcome2.replies should contain only SuccessfulWithdrawalResponse(80) |