mirror of https://github.com/sbt/sbt.git
TaskMap: memoizes task-producing functions
This commit is contained in:
parent
16d6ec7f94
commit
47e9428144
|
|
@ -0,0 +1,20 @@
|
|||
/* sbt -- Simple Build Tool
|
||||
* Copyright 2010 Mark Harrah
|
||||
*/
|
||||
package sbt
|
||||
|
||||
import std._
|
||||
import TaskExtra._
|
||||
import collection.mutable
|
||||
|
||||
object TaskMap
|
||||
{
|
||||
/** Memoizes a function that produces a Task. */
|
||||
def apply[A,B](f: A => Task[B]): A => Task[B] =
|
||||
{
|
||||
val map = new mutable.HashMap[A,Task[B]]
|
||||
a => map.synchronized { map.getOrElseUpdate(a, f(a)) }
|
||||
}
|
||||
/** Lifts `f` to produce a Task and memoizes the lifted function. */
|
||||
def make[A,B](f: A => B): A => Task[B] = apply( a => task(f(a)) )
|
||||
}
|
||||
Loading…
Reference in New Issue