Skip to content
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

Closed
wants to merge 4 commits into from

Conversation

3tty0n
Copy link

@3tty0n 3tty0n commented May 29, 2017

This implements sequental[B](tasks: Seq[Initialize[Task[B]]]) method in TaskSequential.scala and remove useless comment outs.

The return value of sequential[B](tasks: Seq[Initialize[Task[B]]]) is the last one of tasks.

Before:

lazy val tasks = Seq(taskA, taskB, taskC)
test in Test := Def.sequential(tasks.init, tasks.last).value // a little confusing

After:

lazy val tasks = Seq(taskA, taskB, taskC)
test in Test := Def.sequential(tasks).value // looks nice

@eed3si9n eed3si9n added the ready label May 29, 2017
Copy link
Member

@jvican jvican left a 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra 'p' here 😄!

Copy link
Author

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.

@3tty0n
Copy link
Author

3tty0n commented May 30, 2017

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 updated this branch.

@dwijnand
Copy link
Member

dwijnand commented Jun 4, 2017

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]

@jvican
Copy link
Member

jvican commented Jun 4, 2017

That makes sense. Can we special case for list of only one element and return the task itself instead of calling the underlying sequential?

@jvican
Copy link
Member

jvican commented Jun 4, 2017

*for one and zero elements.

@3tty0n
Copy link
Author

3tty0n commented Jun 4, 2017

I agree with this idea.

Can we special case for list of only one element and return the task itself instead of calling the underlying sequential?

@3tty0n
Copy link
Author

3tty0n commented Jun 4, 2017

I will implement and push it when I go back home.

@3tty0n
Copy link
Author

3tty0n commented Jun 4, 2017

I have one problem.
How sequential[B](tasks: Seq[Initialize[Task[B]]]) behave when tasks is Nil ?
It seems good to do nothing, but Task[Unit] is not inferred to Task[B]].


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)
   }

@jvican
Copy link
Member

jvican commented Jun 4, 2017

@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.

@ShaneDelmore
Copy link

What about using a NonEmptySeq?

@3tty0n
Copy link
Author

3tty0n commented Jun 4, 2017

@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.

@dwijnand
Copy link
Member

dwijnand commented Jun 4, 2017

Let's not add partial methods to the API.

@jvican
Copy link
Member

jvican commented Jun 5, 2017

The full of sbt API, both public and internal, is full of them. I see why we shouldn't, honestly.

@jvican
Copy link
Member

jvican commented Jun 5, 2017

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?

@dwijnand
Copy link
Member

dwijnand commented Jun 5, 2017

What's an empty task? Given 0 tasks of B how are you going to return 1 task of B?

@jvican
Copy link
Member

jvican commented Jun 5, 2017

Got confused by the unitTask in SequentialTask. I see two ways to move this forward:

  1. Use https://github.com/tarao/nonempty-scala. Instead of List(1,2,3) we can do NonEmpty(1,2,3) and ensure that the collection is non empty. Pretty neat. The idea would be to port it to sbt/sbt.
  2. Require ::. The major disadvantage with this approach is that 1::Nil returns List not ::. So users of the sequential function asking for a list would need to patmat on the list before calling the method.

IMO, the first one is the best. I can see NonEmpty being useful in other places of the sbt API. I think it's a good idea to port it.

@jvican
Copy link
Member

jvican commented Jun 16, 2017

@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

@3tty0n
Copy link
Author

3tty0n commented Jun 16, 2017

@jvican Thanks. I think porting and using NonEmpty is good way to realize the idea of this PR.

@dwijnand dwijnand changed the base branch from 1.0.x to 1.x July 17, 2017 15:16
@eed3si9n eed3si9n added backlog and removed ready labels Aug 21, 2018
@eed3si9n eed3si9n changed the base branch from 1.x to develop August 31, 2018 04:58
@eed3si9n
Copy link
Member

Looking at this now, I kind of feel like adding NonEmptyList just for this sounds like a maintenance burden. Is Def.sequential(tasks.init, tasks.last).value that bad?

@eed3si9n
Copy link
Member

Closing this in favor of #4369

@eed3si9n eed3si9n closed this Sep 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants