| 12345678910111213141516171819202122232425 |
- extension LetExtension<T> on T {
- /// 类似 Kotlin 的 let 函数,允许对任意对象执行代码块
- R let<R>(R Function(T it) block) {
- return block(this);
- }
- }
- extension ApplyExtension<T> on T {
- /// 类似 Kotlin 的 apply 函数,允许对对象执行配置操作,并返回自身
- T apply(void Function(T it) block) {
- block(this);
- return this;
- }
- }
- extension AlsoExtension<T> on T {
- T also(void Function(T it) block) {
- block(this);
- return this;
- }
- }
- extension RunExtension<T> on T {
- R run<R>(R Function(T it) block) => block(this);
- }
|