Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ask HN: Which are good LINQ equivalents in other languages?
2 points by IanSanders on July 8, 2021 | hide | past | favorite | 7 comments


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<Integer> 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");


Many other languages have similar mechanisms to the Java streams API. Scheme, and probably Lisp in general, is well known for it. Then we have Ruby, Crystal, Python, D, JavaScript...

I can't think of other languages that have something exactly like LINQ, though, unless you count SQL.


Not part of the standard library but querydsl is the closest to it in java.


But this lacks the compact syntax of LINC. I don't think there is a real equivalent in other languages (I don't know F#).


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


Eloquent in PHP/Laravel is a good contender.


F#




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: