3 ms·
while (xs.Any(x => f(x))) { } Pulling things out into other functions makes it even clearer. Though yes, the goto is clearer than the labelled continue. I wou
by ajanuary 14y ago
while (xs.Any(x => f(x))) { }
Pulling things out into other functions makes it even clearer.
Though yes, the goto is clearer than the labelled continue. I wouldn't necessarily agree that it's less error prone though.
- lubutu 14y agoWell, if we permit functional programming languages all the problems concerning imperative control flow magically go away...
- ajanuary 14y agoI just used higher order functions to keep the example short, and I'd use them irl to avoid code repetition. The concept still applies without them: while (fTrueForAny(xs)) { } boolean fTrueForAny(List xs) { for (Item x : xs) { if (f(x)) { return true; } } return false; } There isn't anything non-imperative about higher order functions. var externalDataStore = new ExternalDataStore() [1, 2, 3, 4].each(x => externalDataStore.store(x)) externalDataStore.getItems().each(item => print(item)) Plenty of higher order functions, and plenty of non-functional, ordered, stateful, imperative code.