用apply调用闭包的使用场景?
在ruby-by-example里闭包那一章里讲到捕获变量的时候提到通过
fn apply<F>(f: F) where
F: FnOnce() {
f();
}
方式来调用函数、闭包,但是既然类似的lambda 已经被定义出来了,为什么还需要专门通过这种方式来调用呢?不是直接可以通过这种方式调用了吗?
let closure_inferred = |i | i + 1 ;
closure_inferred(1);
推荐文章: