HACKER Q&A
📣 IanSanders

Which are good LINQ equivalents in other languages?


Which are good LINQ equivalents in other languages?


  👤 Rounin Accepted Answer ✓
In Java, the closest alternative that's part of the standard language is streams. Off the top of my head, it goes something like this:

List numbers = number_list.stream().filter(number -> number > 3).collect(Collectors.toList())

boolean isTrue = Stream.of(boolean_array).anyMatch(Function.identity());

String checkForNull = Optional.ofNullable(some_xml).map(SomeXml::getSomeField).map(SomeField::GetSomeAttribute).orElse("nothing here");


👤 Graffur
Off topic question about LINQ.. when should you use it? C# can be written in s few different ways. Some linq type solutions can be elegant but if the next person updating expects classic c# style it probably isn't the best option

👤 codegeek
Eloquent in PHP/Laravel is a good contender.