Skip to content

Instantly share code, notes, and snippets.

@aludwiko
Last active November 29, 2017 06:04
Show Gist options
  • Save aludwiko/bd380f8b131fec1d9bf105c34e52d842 to your computer and use it in GitHub Desktop.
Save aludwiko/bd380f8b131fec1d9bf105c34e52d842 to your computer and use it in GitHub Desktop.
val infiniteTransactionsStream =
 Stream.continually(s"$randomUser() sent $randomValue() BTC to $randomUser()")
Source(infiniteTransactionsStream)
 .grouped(5) //group transactions into 5 element blocks
 .scan(0.hashCode.toString) { (previousBlockHash, transactions) =>
//hash for block is defined as hash of transactions hash and previous block hash
  (transactions.hashCode(), previousBlockHash).hashCode.toString
 }
.mapAsync(1)(saveHashAndReturnIt)
.runForeach(savedHash => println(s"saved block with hash:$savedHash"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment