Hooks logo

Hooks represent "pluggable" points in a software model. They provide a mechanism for tapping into such points to get updates, or apply additional functionality to some typed object. Included in this project are:

A variety of hooks

Basic, Waterfall, Bail, Loop
With extendable APIs
class MyHook : SyncHook<((HookContext, Int) -> Unit)>() {
    fun call(value: Int) =
        super.call { f, context -> f(context, value) }

    fun tap(name: String, f: ((Int) -> Unit)) =
        super.tap(name) { _, newValue -> f(newValue) }
}

val myHook = MyHook()
And strongly typed methods
myHook.tap("logger") { _, newValue: Int ->
    println("newValue: $newValue")
}
myHook.call(30)
Asynchronous support built on coroutines
class SimpleAsyncHook :
    AsyncSeriesHook<(suspend (HookContext) -> Unit)>() {

    suspend fun call() =
        super.call { f, context -> f(context) }
}

val simple = SimpleAsyncHook()
runBlocking {
    simple.tap("some-network-plugin") {
        // do network call
    }

    simple.call()
}

Kotlin symbol processor

To make hooks easier to use
Paired with a concise DSL that generates type-safe APIs
abstract class SomeHooks : Hooks() {
    @Sync<() -> Unit>
    abstract val syncHook: Hook
}
Wrapped with a Gradle plugin...
plugins {
    id("com.intuit.hooks")
}
And a Maven Kotlin plugin extension
<compilerPlugins>
    <plugin>hooks</plugin>
</compilerPlugins>