Created
December 12, 2025 11:59
-
-
Save andiogenes/99bafc13b19907a8dac32bceace11b36 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sbt.* | |
| /** Creates [[Def.Setting]] from [[SettingKey]] manipulating with [[State]], by assigning an action | |
| * that will perform previous action assigned to this key, and then evaluate parameter `hook`, | |
| * which may access and modify setting's state. | |
| * | |
| * @example | |
| * {{{ | |
| * lazy val someProject = (project in file("some")) | |
| * .settings( | |
| * addHook(Global / onLoad) { s => | |
| * println(s"Loaded! Current state: $s") | |
| * s | |
| * } | |
| * ) | |
| * }}} | |
| */ | |
| def addHook(settingKey: SettingKey[State => State])(hook: State => State) = | |
| settingKey := settingKey.value.andThen(hook) | |
| /** Version of [[addHook]] for `hooks` that only perform side effect. | |
| * | |
| * @example | |
| * {{{ | |
| * lazy val someProject = (project in file("some")) | |
| * .settings( | |
| * addIdempotentHook(Global / onLoad) { | |
| * println("Loaded! No access to the state.") | |
| * } | |
| * ) | |
| * }}} | |
| */ | |
| def addIdempotentHook(settingKey: SettingKey[State => State])(hook: => Unit) = | |
| addHook(settingKey)(s => { hook; s }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment