nc-photos/lib/object_extension.dart
2022-01-06 18:55:46 +08:00

18 lines
429 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);
}