We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
The special case for handling n = 1 in the implementation of takeViaUnfold is not necessary:
n = 1
takeViaUnfold
fpinscala/answerkey/laziness/13.answer.scala
Lines 7 to 12 in 71a7931
It's already covered by the general case:
case (Cons(h,t), n) if n > 1 => Some((h(), (t(), n-1)))
Test:
test("takeUnfold") { assertEquals(Stream(1, 2, 3).takeUnfold(0).toList, List.empty) assertEquals(Stream(1, 2, 3).takeUnfold(1).toList, List(1)) assertEquals(Stream(1, 2, 3).takeUnfold(2).toList, List(1, 2)) assertEquals(Stream(1, 2, 3).takeUnfold(5).toList, List(1, 2, 3)) }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The special case for handling
n = 1
in the implementation oftakeViaUnfold
is not necessary:fpinscala/answerkey/laziness/13.answer.scala
Lines 7 to 12 in 71a7931
It's already covered by the general case:
Test:
The text was updated successfully, but these errors were encountered: