mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 16:56:19 +01:00
26 lines
690 B
Dart
26 lines
690 B
Dart
import 'dart:async';
|
|
|
|
extension ObjectExtension<T> on T {
|
|
/// Run [fn] with this, and return this
|
|
T apply(void Function(T obj) fn) {
|
|
fn(this);
|
|
return this;
|
|
}
|
|
|
|
/// Run [fn] with this, and return this
|
|
Future<T> applyFuture(FutureOr<void> Function(T obj) fn) async {
|
|
await fn(this);
|
|
return this;
|
|
}
|
|
|
|
/// Run [fn] with this, and return the results of [fn]
|
|
U run<U>(U Function(T obj) fn) => fn(this);
|
|
|
|
/// Run [fn] with this, and return the results of [fn]
|
|
Future<U> runFuture<U>(FutureOr<U> Function(T obj) fn) async {
|
|
return await fn(this);
|
|
}
|
|
|
|
/// Cast this as U, or null if this is not an object of U
|
|
U? as<U>() => this is U ? this as U : null;
|
|
}
|