Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

added scanLeft #26

wants to merge 1 commit into from

Conversation

utgheith
Copy link

@utgheith utgheith commented Apr 7, 2021

A useful and commonly implemented API.

Copy link

@c-meier c-meier left a 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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var acc = initial
var acc = initial
f(acc)

Comment on lines +66 to +67
assert(Generator(1,2,3,4).scanLeft(100)(_ + _).toList == List(101,103,106,110))
assert(Generator[Int]().scanLeft(100)(_ + _).toList == List())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants