Skip to main content

Chaining

Dagger Functions can return custom objects, which in turn can define new functions. This allows for "chaining" of functions in the same style as the core Dagger API.

So long as your object can be JSON-serialized, its state will be preserved and passed to the next function in the chain.

Here is an example module with support for function chaining:

import { object, func, field } from "@dagger.io/dagger"

@object()
class MyModule {
@field()
greeting = "Hello"

@field()
name = "World"

@func()
withGreeting(greeting: string): MyModule {
this.greeting = greeting
return this
}

@func()
withName(name: string): MyModule {
this.name = name
return this
}

@func()
message(): string {
return `${this.greeting} ${this.name}`
}
}

And here is an example call for this module:

dagger call with-name --name=Monde with-greeting --greeting=Bonjour message

The result will be:

Bonjour, Monde!