-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 replicateA to Applicative #823 #830
Conversation
Current coverage is
|
Can you add a test case for this, either as sbt-doctest or a plain test? |
I don't "have the skill" for that yet. Scalacheck/property-based testing are pretty much next on my list. Should I hold off on this PR until I can get that grokked and wrapped up? |
@adelbertc At this point the tests aren't making a ton of sense to me. Is there a similar test on a similar method I can look at to get the idea enough to just get that done? |
@lukewyman The process will go something like this:
An example of a test can be found https://github.com/non/cats/blob/master/tests/src/test/scala/cats/tests/FoldableTests.scala#L56 so you would have something like class ApplicativeTests extends CatsSuite {
test("replicateA") {
val applicative = Applicative[Option]
/* test here */
}
} |
Also one very small quibble with the comment on the method. Also, I think it's worth explaining the effect of using def alsoReplicate[A](n: Int, fa: F[A]): F[List[A]] =
fa.map { a => List.fill(n)(a) } Do you all think something like this would work?
|
In general, given the prevalence of I don't want to derail this PR, which seems fine, but just wondering is there some principle about when such specialisations to something like @non that proposed comment update seems fine to me. Difficult operation to capture the implications of succinctly, but a couple of examples would also go a long way to clarifying the effect and add a lot of value, particularly the implications if scala> Applicative[List].replicateA(2, List(1, 2))
res8: List[List[Int]] = List(List(1, 1), List(1, 2), List(2, 1), List(2, 2))
scala> Applicative[Option].replicateA(2, Option(2))
res9: Option[List[Int]] = Some(List(2, 2)) |
@mikejcurry I'm still very much a newbie to Scala and FP in general, so this was a learning experience for me. If |
Don't take my comment the wrong way. I'm pretty new myself. It was just a question. :-). Same as you, just learning. :-). I'd definitely add some sbt-doctest with examples to the scaladoc though. Some good examples in Foldable.scala here: https://github.com/ceedubs/cats/blob/1ae5d583d935d6d8bd7b2cce1d39f6a181a05ac6/core/src/main/scala/cats/Foldable.scala#L87-L104 Basically, it is where you add some code and the result that would be expected at a REPL, and the build will verify that the output is correct. This in turn ensures that there are examples right in the scaladoc for folks reading the API and ensures that the examples that are shipped compile. |
@adelbertc I've added a unit test for #823. Good to go? |
@@ -29,6 +30,12 @@ import simulacrum.typeclass | |||
def pureEval[A](x: Eval[A]): F[A] = pure(x.value) | |||
|
|||
/** | |||
* Given fa and n, apply fa n times to construct an F[List[A]] value. |
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.
This might render a little cleaner in the ScalaDoc if you use backticks around fa
, n
, and F[List[A]]
.
👍 thanks! |
Looks like Travis 2.10 failed, rebuilding. 👍 on green. |
The build had failed again with a mysterious error. I restarted it again, but I just realized that there are now merge conflicts :(. Sorry @lukewyman would you mind updating your branch? |
Hey @ceedubs, I've updated the PR so that it merges. All green :) |
👍 thanks! |
Added replicateA to Applicative #823
Hi @mikejcurry, I believe you can go ahead and close this one. |
Added replicateA to Applicative. Other combinators suggested already existed by other names.