4 ms·
Works well meaning don't use functional calls at all if you want to escape from them.
by delsalk 12y ago
Works well meaning don't use functional calls at all if you want to escape from them.
- baddox 12y agoI've just never encountered that use case in Ruby code, and to me it feels like really bad style. You can use .find to find the first element that matches a block, then return that item (if one exists).
- delsalk 12y agoIt doesn't look like fantastic Ruby code, you're right. I just wouldn't agree that JS "works well" when it comes to their somewhat afterthought functional iterators.
- baddox 12y agoWhat doesn't work well? The only thing I can think of, which comes up on occasion, is that you can't manually stop iteration in forEach without ugly tricks like throwing and catching an exception. I actually wanted that behavior for the first time recently, so I just used JQuery's each which lets you stop iteration by returning false. I'm assuming other JS utility libraries like underscore provide something similar.