Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Stream vs. LINQ = jLinqer

Stream vs. LINQ = jLinqer

"jLinqer" is a Java implementation of LINQ.
https://github.com/k--kato/jLinqer

Keisuke KATO

July 03, 2015
Tweet

More Decks by Keisuke KATO

Other Decks in Programming

Transcript

  1. async function aboutMe() { let profile = { name: “Keisuke

    Kato” , twitter: “@k_kato” }; return await followTwitterAsync(profile); }
  2. Stream vs. LINQ ‡Wikipedia, “Language Integrated Query”, https://en.wikipedia.org/wiki/Language_Integrated_Query ‡Wikipedia, “Anders

    Hejlsberg”, https://en.wikipedia.org/wiki/Anders_Hejlsberg ‡O'reilly, ”C#: Yesterday, Today, and Tomorrow: An Interview with Anders Hejlsberg, Part 1”, http://archive.oreilly.com/pub/a/dotnet/2005/10/17/interview-with-anders-hejlsberg.html Stream LINQ Language Java C#, F#, VB, Delphi Since 2014 2007 Developer Oracle Microsoft Influenced by ? SQL, Haskell
  3. All you need is metaphors ‡Wikipedia, George Lakoff and Mark

    Johnson, “Conceptual metaphor”, https://en.wikipedia.org/wiki/Conceptual_metaphor
  4. Software Metaphors ‡Steve McConnell, “Code Complete, Second Edition”, https://www.safaribooksonline.com/library/view/code-complete-second/0735619670/ch02s03.html David

    Gries science 1981 Donald Knuth art 1998 Watts Humphrey process 1989 P. J. Plauger and Kent Beck driving a car 1993, 2000 Alistair Cockburn game 2002 Eric Raymond bazaar 2000 Andy Hunt and Dave Thomas gardening 1999 Paul Heckel filming Snow White and the Seven Dwarfs 1994 Fred Brooks farming, hunting werewolves, or drowning with dinosaurs in a tar pit 1995
  5. filter vs. Where Java C# @Test public void filter() throws

    Exception { // arrange List<Integer> list = Arrays.asList(1, 2, 3); // act Stream<Integer> stream = list.stream().filter(x -> x == 1 || x == 3); List<Integer> actual = stream.collect(Collectors.toList()); // assert assertEquals(true, actual.contains(1)); assertEquals(false, actual.contains(2)); assertEquals(true, actual.contains(3)); } [TestMethod] public void Where() { // arrange List<int> list = new List<int>() { 1, 2, 3 }; // act IEnumerable<int> enumerable = list.Where(x => x == 1 || x == 3); List<int> actual = enumerable.ToList(); // assert Assert.AreEqual(true, actual.Contains(1)); Assert.AreEqual(false, actual.Contains(2)); Assert.AreEqual(true, actual.Contains(3)); }
  6. sort vs. OrderBy Java C# @Test public void orderBy() {

    // arrange java.util.List<String> list = Arrays.asList("b", "c", "a"); // act Stream<String> stream = list.stream().sorted(); List<String> actual = stream.collect(Collectors.toList()); // assert assertEquals("a", actual.get(0)); assertEquals("b", actual.get(1)); assertEquals("c", actual.get(2)); } [TestMethod] public void Where() { // arrange List<string> list = new List<string>() { “b”, “c”, “a” }; // act IEnumerable<string> enumerable = list.OrderBy(x => x); List<string> actual = enumerable.ToList(); // assert Assert.AreEqual(“a”, actual[0]); Assert.AreEqual(“b”, actual[1]); Assert.AreEqual(“c”, actual[2]); }
  7. Stream + LINQ = jLinqer ‡Qiita, “Java に C# の

    LINQ を移植してみた – jLinqer”, http://qiita.com/k--kato/items/ec7ab8b392fa8bb0a732
  8. Stream + LINQ = jLinqer ‡GutHub, “jLinqer”, https://github.com/k--kato/jLinqer LINQ(C#) jLinqer(Java)

    Stream(Java) ThenBy thenBy n/a ThenByDescending thenByDescending n/a SkipWhile skipWhile n/a TakeWhile takeWhile n/a Intersect intersect n/a Union union n/a Except except n/a Reverse reverse n/a SequenceEqual sequenceEqual n/a OfType ofType n/a ElementAt elementAt n/a
  9. jLinqer @ Maven Central ‡Maven Central, “jLinqer”, https://oss.sonatype.org/content/groups/public/com/github/jlinqer/jlinqer/0.1.0/ ‡Sonatype. “Community

    Support - Open Source Project Repository HostingOSSRH-16339”, https://issues.sonatype.org/browse/OSSRH-16339 <dependency> <groupId>com.github.jlinqer</groupId> <artifactId>jlinqer</artifactId> <version>0.1.0</version> </dependency>
  10. Type-Erasure Problem ‡stackoverflow, “Generic method to perform a map-reduce operation.

    (Java-8)”, http://stackoverflow.com/questions/30826674/generic-method-to-perform-a-map-reduce-operation-java-8