Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sbt 0.13 task macro equivalent of flatMap

Tags:

scala

sbt

I'm upgrading my build to use the new macro syntax as much as I can, and I encountered a flatMap that I don't know how to deal with.

Let's say I used to have a task of the following form

myTask <<= (foo, bar) flatMap { (x, y) => someFunctionProducingATask(x, y, 5) }

Now, Def.taskDyn looks vaguely promising, but doesn't quite fit. Translating it to the naive thing doesn't work:

myTask <<= Def.taskDyn {
  val x = foo.value
  val y = bar.value
  someFunctionProducingATask(x, y, 5) // ERROR: we need an Initialize[Task[...]], but have a Task[...]
}

Initialize feels monadic but I can't find a pure for it, so I don't know how to put my task into it, or if that's even desirable. The docs don't seem to say anything beyond suggesting I use taskDyn. Anyone have any ideas here?

like image 577
Mysterious Dan Avatar asked Jul 26 '13 18:07

Mysterious Dan


1 Answers

In most user-facing documentation, "task" means Initialize[Task[T]]. A "task" as builds and plugins usually use them is really a setting whose value is a task.

The someFunctionProducatATask should probably return Initialize[Task[T]].

pure for Initialize is Def.value (accepts => T) or Def.pure (accepts () => T).

However, normally just use Def.task (for Initialize[Task[T]]) and Def.setting (for Initialize[T]. These allow the same syntax as the argument to :=, +=, and ++=.

like image 156
Mark Harrah Avatar answered Sep 28 '22 04:09

Mark Harrah