Last active
August 31, 2015 18:55
-
-
Save wheaties/03ce4d48ead513c57015 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
| //historical chain of value. | |
| import java.concurrent.ConcurrentSkipListMap | |
| class History[Token, A, B](tk: => Token, prev: ConcurrentSkipListMap[Token, A], id: A => B){ | |
| def apply(f: A => A): (Token, B) ={ | |
| val token = tk | |
| (token, id(update(token, f))) | |
| } | |
| def map[C](f: B => C) = new History(prev, id andThen f) | |
| def flatMap[C](f: B => History[Token, A, C]) ={ | |
| val entry = prev.lastEntry().getValue() | |
| f(id(entry)) | |
| } | |
| protected def update(token: Token, f: A => A): A ={ | |
| val entry = prev.lastEntry().getValue() | |
| val value = f(entry) | |
| prev.put(token, value) | |
| value | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment