Skip to content

Instantly share code, notes, and snippets.

@hohonuuli
Last active December 19, 2017 23:26
Show Gist options
  • Save hohonuuli/08ba22d87a208a9e51fea489d247d34d to your computer and use it in GitHub Desktop.
Save hohonuuli/08ba22d87a208a9e51fea489d247d34d to your computer and use it in GitHub Desktop.
import java.time.Instant
trait Transaction {
def label: String
/** The amount of money in the transaction */
def value: Double
/** When this transaction occurs */
def date: Instant
/**
* Most events reoccur or repeat. This returns Some if there is another event,
* None if it's the last even in the sequence
*/
def next: Option[Transaction]
/** The accumlated value of an event as it progresses in time */
def accumulatedValue: Double
def stream: Stream[Transaction] = {
def loop(b0: Transaction): Stream[Transaction] = {
b0.next match {
case Some(b1) => b0 #:: loop(b1)
case None => b0 #:: Stream.empty[Transaction]
}
}
loop(this)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment