-
Notifications
You must be signed in to change notification settings - Fork 929
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
Implement sequential[B](tasks: Seq[Initialize[Task[B]]]) and remove useless coment outs #3230
Conversation
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.
Hey @3tty0n, tihs looks great! I've always wondered why it wasn't easier to do this. LGTM.
Thanks for taking the time to report the issue and address it in a PR. Small changes matter 😄.
@@ -0,0 +1,5 @@ | |||
### Impprovements |
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.
Extra 'p' 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.
Thank you for your quick reply!
I'll fix it as soon as possible.
…seless comment outs
70c90fe
to
bf52a01
Compare
I fixed the typo in the notes, but the CI was failed (even though the previous CI test was succeessful). Should I update the branch? EDIT: |
I don't like the addition of this overload because it could fail Nil. Put differently: it uses init and last which aren't partial functions. [edit: ... which are* partial functions] |
That makes sense. Can we special case for list of only one element and return the task itself instead of calling the underlying sequential? |
*for one and zero elements. |
I agree with this idea.
|
I will implement and push it when I go back home. |
I have one problem. def sequential[B](tasks: Seq[Initialize[Task[B]]]): Initialize[Task[B]] =
tasks.toList match {
case Nil => ???
case x :: Nil => Def.task { x.value }
case _ =>
sequential(tasks.init.map(unitTask), tasks.last)
} |
04ad045
to
f9d9659
Compare
@3tty0n Given the tradition of sbt of throwing exceptions all over the place, I would just throw an exception if the list is zero, and document it with Scaladoc. |
What about using a NonEmptySeq? |
@jvican Thanks. I will try it as you told me. @ShaneDelmore NonEmptySeq is built-in data structure? If not, I think using NonEmptySeq is not recommended. |
Let's not add partial methods to the API. |
The full of sbt API, both public and internal, is full of them. I see why we shouldn't, honestly. |
Okay, I agree this is far than ideal. What if we just return an empty task if the argument of sequential is empty? Then we're total. We should document it well in the public API. Are you happier with this @dwijnand? |
What's an empty task? Given 0 tasks of |
Got confused by the
IMO, the first one is the best. I can see |
@3tty0n I think the best solution is to port https://github.com/tarao/nonempty-scala to sbt. It would be a very meaningful addition because it would allow us to enforce better the contract of the APIs and ensuring that collections are non-empty by design. Then, we can use it in the following way: lazy val tasks = NonEmpty(taskA, taskB, taskC)
test in Test := Def.sequential(tasks).value /cc @eed3si9n |
@jvican Thanks. I think porting and using |
Looking at this now, I kind of feel like adding NonEmptyList just for this sounds like a maintenance burden. Is |
Closing this in favor of #4369 |
This implements
sequental[B](tasks: Seq[Initialize[Task[B]]])
method inTaskSequential.scala
and remove useless comment outs.The return value of
sequential[B](tasks: Seq[Initialize[Task[B]]])
is the last one oftasks
.Before:
After: