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
Add Iterant.interleave #524
Merged
alexandru
merged 6 commits into
monix:master
from
greenhat:issue-498-add-iterant-interleave
Jan 18, 2018
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
eef5316
Add method signature and scaladoc;
greenhat a1be4b5
Update AUTHORS;
greenhat a7185f6
Add naiveImp for interleave (for tests);
greenhat ca9e4f7
Remove subtyping relationship;
greenhat 355b386
Draft `Iterant.interleave` implementation;
greenhat be3b0d4
Add tests to check earlyStop preservation and sequential processing;
greenhat File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
monix-tail/shared/src/main/scala/monix/tail/internal/IterantInterleave.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (c) 2014-2018 by The Monix Project Developers. | ||
* See the project homepage at: https://monix.io | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package monix.tail.internal | ||
|
||
import cats.effect.Sync | ||
import monix.tail.Iterant | ||
|
||
|
||
private[tail] object IterantInterleave { | ||
def apply[F[_], A, B >: A](lh: Iterant[F, A], rh: Iterant[F, B]) (implicit F: Sync[F]): Iterant[F, B] = { | ||
rh | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
monix-tail/shared/src/test/scala/monix/tail/IterantInterleaveSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (c) 2014-2018 by The Monix Project Developers. | ||
* See the project homepage at: https://monix.io | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package monix.tail | ||
|
||
import cats.effect.Sync | ||
import monix.eval.Coeval | ||
import monix.execution.internal.Platform | ||
import org.scalacheck.Test | ||
import org.scalacheck.Test.Parameters | ||
|
||
object IterantInterleaveSuite extends BaseTestSuite { | ||
override lazy val checkConfig: Parameters = { | ||
if (Platform.isJVM) | ||
Test.Parameters.default.withMaxSize(256) | ||
else | ||
Test.Parameters.default.withMaxSize(32) | ||
} | ||
|
||
private def naiveImp[F[_], A, B >: A](lh: Iterant[F, A], rh: Iterant[F, B]) | ||
(implicit F: Sync[F]): Iterant[F, B] = | ||
lh.zip(rh).flatMap { case (a, b) => Iterant[F].pure(a) ++ Iterant[F].pure(b) } | ||
|
||
test("naiveImp smoke test") { implicit s => | ||
assertEquals(naiveImp( | ||
Iterant[Coeval].of(11, 12), | ||
Iterant[Coeval].of(21, 22, 23)).toListL.value, | ||
List(11, 21, 12, 22)) | ||
assertEquals(naiveImp( | ||
Iterant[Coeval].of(11, 12), | ||
Iterant[Coeval].of(21)).toListL.value, | ||
List(11, 21)) | ||
} | ||
|
||
// TODO equivalence test with naive imp | ||
|
||
// TODO various scenarios (stop on error, etc.) | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Just a small comment — you don't need the subtyping relationship to avoid covariance issues here, i.e. you don't need a
B
type parameter.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.
Or in other words, it's OK to have it on the method in
Iterant
, but not on this function here.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.
@alexandru If I remove
B
inapply
:I get error:
Do you want to remove
B
fromIterant.interleave
?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.
Ah, true,
Iterant
is invariant for now as a design decision having to do with covariance not mixing well with higher kinds, but you can useself.upcast[B]
in that call.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.
@alexandru Thanks! Done. I saw
upcast
but did not think of using it here.