3 ms·
One situation I haven't found a good construct for yet is iterating over a list to do some work unrelated to the list ie foreach(i in list){ if i == 0 { class
by setr 8y ago
One situation I haven't found a good construct for yet is iterating over a list to do some work unrelated to the list ie
foreach(i in list){
if i == 0 { class.a() }
else { class.b() }
}
- goalieca 8y agoBut foreach is a function. The weird thing about your pattern is that class.a() and class.b() may have side effects and don’t seem to depend on i at all. If I were to optimize this loop or even make it parallel, then I’m certainly missing some information. Some information that could be captured by another expression.