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

Sequences And Arrays: Change type of res0: from List to Seq #91

Merged
merged 2 commits into from Dec 10, 2017

Conversation

Samehadar
Copy link
Contributor

If you try to compile with List[String] you receive type mismatch error:
"Error:() type mismatch;
found : Seq[String]
required: List[String]
val r: List[String] = s map {"

If you try to compile with List[String] you receive type mismatch error:
"Error:() type mismatch;
 found   : Seq[String]
 required: List[String]
    val r: List[String] = s map {"
@manufacturist
Copy link

manufacturist commented Nov 2, 2017

Shouldn't both answers be accepted, even though r is of type Seq[String]?

val s = Seq("hello", "world")
val r = s map {
  _.reverse
}

r.isInstanceOf[Seq[String]]
//true

r == Seq("olleh", "dlrow")
//true

r.isInstanceOf[List[String]]
//true

r == List("olleh", "dlrow")
//true

I mean, the List type does extend AbstractSeq:

abstract class AbstractSeq[+A] extends AbstractIterable[A] with Seq[A]

EDIT:
Actually anything that extends the AbstractSeq should be accepted, right?

Copy link
Member

@raulraja raulraja left a comment

Choose a reason for hiding this comment

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

@Samehadar thanks for your contribution

@raulraja raulraja merged commit d78c8ea into scala-exercises:master Dec 10, 2017
@Samehadar Samehadar deleted the patch-1 branch December 11, 2017 17:57
@Samehadar Samehadar restored the patch-1 branch December 11, 2017 17:57
@Samehadar Samehadar deleted the patch-1 branch December 11, 2017 17:57
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.

None yet

3 participants