-
Notifications
You must be signed in to change notification settings - Fork 1
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
solution2.2.6.1 provided #53
Conversation
Signed-off-by: Andreas Roehler <andreas.roehler@online.de>
Signed-off-by: Andreas Roehler <andreas.roehler@online.de>
Signed-off-by: Andreas Roehler <andreas.roehler@online.de>
False error?:
|
That's where the problem is. Remove the type annotation and you get |
|
||
def fromPairs[A](xs: Seq[(A, A)]): Seq[A] = { | ||
var b: Seq[A] = List() | ||
xs.map((x: (A, A)) => (b = b :+ (x: (A, A))(0) :+ (x: (A, A))(1))) |
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.
The function for extracting the parts from the tuple are _1
and _2
. The syntax x(0)
will not work with tuples until Scala 3.
Also, the point of this exercise is to use flatMap
or flatten
for implementing fromPairs
, instead of using var b
and mutating b
in a loop.
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.
Okay, thanks. Should provide the alternative solutions too.
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.
Will you write a solution using flatMap or flatten in a different PR?
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.
Would prefer that, as comments are easier to read then. But do, as it's convenient for you.
Signed-off-by: Andreas Roehler <andreas.roehler@online.de>
No description provided.