-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Added parFlatMapN
#4243
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 parFlatMapN
#4243
Changes from 6 commits
a0e0efb
fe96ffa
f62d98b
997e803
06ac73b
5e41658
adbb470
c8b6cd0
325b4b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -390,6 +390,38 @@ class ParallelSuite | |
| } | ||
| } | ||
|
|
||
| test("ParFlatMapN over List should be consistent with parMapN flatten") { | ||
| forAll { (as: List[Int], bs: List[Int], cs: List[Int]) => | ||
| val mf: (Int, Int, Int) => List[Int] = _ :: _ :: _ :: Nil | ||
|
satorg marked this conversation as resolved.
Outdated
|
||
| assert((as, bs, cs).parFlatMapN(mf) == (as, bs, cs).parMapN(mf).flatten) | ||
| } | ||
| } | ||
|
|
||
| test("ParFlatMapN over NonEmptyList should be consistent with parMapN flatten") { | ||
| forAll { (as: NonEmptyList[Int], bs: NonEmptyList[Int], cs: NonEmptyList[Int]) => | ||
| val mf: (Int, Int, Int) => NonEmptyList[Int] = (a, b, c) => NonEmptyList.of(a, b, c) | ||
| assert((as, bs, cs).parFlatMapN(mf) == (as, bs, cs).parMapN(mf).flatten) | ||
| } | ||
| } | ||
|
|
||
| test("ParFlatMap over List should be consistent with flatmap") { | ||
| forAll { as: List[Int] => assert(Tuple1(as).parFlatMap(_ :: Nil) == Tuple1(as).flatMap(_ :: Nil)) } | ||
| } | ||
|
|
||
| test("ParFlatMap over NonEmptyList should be consistent with flatmap") { | ||
| forAll { as: NonEmptyList[Int] => | ||
| assert(Tuple1(as).parFlatMap(NonEmptyList.one) == Tuple1(as).flatMap(NonEmptyList.one)) | ||
| } | ||
| } | ||
|
|
||
| test("ParMapN over f should be consistent with parFlatMapN over f lifted in Kleisli") { | ||
| forAll { (as: List[Int], bs: List[Int]) => | ||
| val f: (Int, Int) => Int = _ + _ | ||
| val mf: (Int, Int) => List[Int] = Function.untupled(Kleisli.fromFunction[List, (Int, Int)](f.tupled).run) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what Kleisli is doing here. Couldn't we just do:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not very much, my intention was to show that
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just pushed this val f: (Int, Int) => Int = (a, b) => a + b
val mf: (Int, Int) => List[Int] = (a, b) => List(a + b) |
||
| assert((as, bs).parMapN(f) == (as, bs).parFlatMapN(mf)) | ||
| } | ||
| } | ||
|
|
||
| test("ParTupled of NonEmptyList should be consistent with ParMap of Tuple.apply") { | ||
| forAll { (fa: NonEmptyList[Int], fb: NonEmptyList[Int], fc: NonEmptyList[Int], fd: NonEmptyList[Int]) => | ||
| assert((fa, fb, fc, fd).parTupled === ((fa, fb, fc, fd).parMapN(Tuple4.apply))) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.