mirror of https://github.com/sbt/sbt.git
Implement Append for Function1
This commit is contained in:
parent
14bffefef9
commit
53c6299c94
|
|
@ -101,4 +101,13 @@ object Append {
|
||||||
def appendValues(a: Seq[Source], b: Seq[File]): Seq[Source] =
|
def appendValues(a: Seq[Source], b: Seq[File]): Seq[Source] =
|
||||||
a ++ b.map(new Source(_, AllPassFilter, NothingFilter))
|
a ++ b.map(new Source(_, AllPassFilter, NothingFilter))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
implicit def appendFunction[A, B]: Value[A => A, A => A] = _.andThen(_)
|
||||||
|
|
||||||
|
implicit def appendSideEffectToFunc[A, B]: Value[A => B, () => Unit] = (f, sideEffect) => {
|
||||||
|
f.andThen { b =>
|
||||||
|
sideEffect()
|
||||||
|
b
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* sbt
|
||||||
|
* Copyright 2011 - 2018, Lightbend, Inc.
|
||||||
|
* Copyright 2008 - 2010, Mark Harrah
|
||||||
|
* Licensed under Apache License 2.0 (see LICENSE)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package sbt
|
||||||
|
|
||||||
|
object AppendSpec {
|
||||||
|
val onLoad = SettingKey[State => State]("onLoad")
|
||||||
|
|
||||||
|
import Scope.Global
|
||||||
|
import SlashSyntax0._
|
||||||
|
|
||||||
|
def doSideEffect(): Unit = ()
|
||||||
|
|
||||||
|
Global / onLoad := (Global / onLoad).value.andThen { s =>
|
||||||
|
doSideEffect()
|
||||||
|
s
|
||||||
|
}
|
||||||
|
|
||||||
|
Global / onLoad += { (s: State) =>
|
||||||
|
doSideEffect()
|
||||||
|
s
|
||||||
|
}
|
||||||
|
|
||||||
|
Global / onLoad += doSideEffect _
|
||||||
|
Global / onLoad += (() => doSideEffect())
|
||||||
|
Global / onLoad += (() => println("foo"))
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue