Last active
December 19, 2017 23:26
-
-
Save hohonuuli/08ba22d87a208a9e51fea489d247d34d to your computer and use it in GitHub Desktop.
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 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