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?
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 ++=
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With