-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added scanLeft #26
base: main
Are you sure you want to change the base?
added scanLeft #26
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the Scala collection API, scanLeft
returns initial
as the first element.
@@ -297,6 +298,16 @@ object Generator{ | |||
override def toString = s"$inner.map($func)" | |||
} | |||
|
|||
private class Scanned[+T, V](inner: Generator[V], initial: T, func: (T,V) => T) extends Generator[T]{ | |||
def generate(f: T => Generator.Action) = { | |||
var acc = initial |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var acc = initial | |
var acc = initial | |
f(acc) |
assert(Generator(1,2,3,4).scanLeft(100)(_ + _).toList == List(101,103,106,110)) | ||
assert(Generator[Int]().scanLeft(100)(_ + _).toList == List()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert(Generator(1,2,3,4).scanLeft(100)(_ + _).toList == List(101,103,106,110)) | |
assert(Generator[Int]().scanLeft(100)(_ + _).toList == List()) | |
assert(Generator(1,2,3,4).scanLeft(100)(_ + _).toList == List(100,101,103,106,110)) | |
assert(Generator[Int]().scanLeft(100)(_ + _).toList == List(100)) |
A useful and commonly implemented API.