scope library

Functional-style helpers for transforming values and managing scope.

Use let to transform a value, also to observe it without changing it, and use to pair synchronous work with cleanup. use runs its disposer in a finally block and does not manage asynchronous resource lifetimes.

Extensions

AlsoExtension on T
Extension for executing side effects while returning the original value.
ApplyExtension on T
Extension for conditionally transforming values.
LetExtension on T
Extension for transforming values using a block function.
TakeExtension on T
Extension for conditionally filtering values.

Functions

run<R extends Object?>(R block()) → R
Executes a code block and returns its result.
use<R extends Object?, T extends Object?>(T value, R block(T value), {void dispose(T value)?}) → R
Executes a block with a value and ensures cleanup via disposal.