Live data from Hacker News

Show HN: Motif – Scala-like pattern matching with Java 8

github.com

11–20 of 36 posts

Re: Show HN: Motif – Scala-like pattern matching with Java 8

#11
post #5

Funny, I happened to code something just today very similar, but a lot lighter (just two classes, Match for consuming only, and MatchMap for mapping the optional. No when/get, just a when taking two parameters : the predicate and the mapping function. public class MatchMap { private final Optional opt; private final U defaultValue; private final AtomicReference result = new AtomicReference (); private MatchMap(Option…

I'd love to see how code using your version compares to code using the OP's version. Got any similar examples?

I use it especially for enums so it's like:

  MatchMap.of(someOptional, defaultValue)
    .whenEquals(MyEnum.VALUEX, v -> someFn(p1, p2))
    .whenEquals(MyEnum.VALUEY, v -> otherFn(p1, p2))
    .resolve();

Re: Show HN: Motif – Scala-like pattern matching with Java 8

#12
post #10

Earlier quoted context omitted.

If you've ever endured the compilation time of a Scala codebase that has more than, say, 2000+ classes, then you might think that some things just aren't meant to happen in Scala either. I used Scala for 4+ years at a company that spent a non-trivial amount of time and resources speeding up its Scala builds (way more than 2000+ classes), sometimes doing sadly controversial things[1] to achieve that speedup. It was a…

If you stick to the same kind of subset in Scala, then compilation isn't that much worse than Java, IME. It's only when you're using a lot of implicits and/or a lot of type inference that compile times go through the roof. (and FWIW I'd say that 2000+ classes - that's what, 600KLOC? - implies a project that should be split up with clear boundaries (i.e. separate release cycles, documented public APIs between them), i…

Some companies, like Twitter and Facebook, are doing this development pattern of mono repo... So even if there are architectural lines to be found, they are eschewing that in favor of keeping versions and APIs closer together.

I can't say I understand that strategy completely but I have also never worked on machinery the size and complexity of Facebook or Twitter.

Re: Show HN: Motif – Scala-like pattern matching with Java 8

#13

Hard to read in comparison to Scala. It's impressive that it was accomplished but some things just aren't meant to happen in Java 8.

If you've ever endured the compilation time of a Scala codebase that has more than, say, 2000+ classes, then you might think that some things just aren't meant to happen in Scala either. I used Scala for 4+ years at a company that spent a non-trivial amount of time and resources speeding up its Scala builds (way more than 2000+ classes), sometimes doing sadly controversial things[1] to achieve that speedup. It was a…

Still at that company, and still enduring long compile times.

Re: Show HN: Motif – Scala-like pattern matching with Java 8

#14
post #7
post #6

The Cambrian explosion of java 8 functional libraries like this is fun to watch. Others I've come across: - http://javaslang.com/ - https://github.com/aol/cyclops - http://totallylazy.com/ - https://github.com/poetix/octarine - (good ol') http://www.functionaljava.org/ The syntax for these libraries is always a little wonky though. If only these libraries also had some sort of syntax preprocessor to make it more pala…

Exactly. I want to like these things, but they're just way to painful on the eyes.

whoosh?

http://www.scala-lang.org/

Re: Show HN: Motif – Scala-like pattern matching with Java 8

#15
post #7

Earlier quoted context omitted.

Exactly. I want to like these things, but they're just way to painful on the eyes.

whoosh? http://www.scala-lang.org/

He said he wanted something that's not painful on the eyes.

Re: Show HN: Motif – Scala-like pattern matching with Java 8

#16
post #5

Earlier quoted context omitted.

I'd love to see how code using your version compares to code using the OP's version. Got any similar examples?

I use it especially for enums so it's like: MatchMap.of(someOptional, defaultValue) .whenEquals(MyEnum.VALUEX, v -> someFn(p1, p2)) .whenEquals(MyEnum.VALUEY, v -> otherFn(p1, p2)) .resolve();

I haven't tried it with enums, but it should still be possible with Motif. I'll have to add some tests.

  match(enumValOpt)
      .when(some(eq(MyEnum.VALUEX))).then(() -> someFn(p1, p2))
      .when(some(eq(MyEnum.VALUEY))).then(() -> otherFn(p1, p2))
      .orElse(defaultValue)
      .doMatch();
It's a little longer than your example since there is support for more than just Optional, but it's pretty similar.

Re: Show HN: Motif – Scala-like pattern matching with Java 8

#17

Funny, I happened to code something just today very similar, but a lot lighter (just two classes, Match for consuming only, and MatchMap for mapping the optional. No when/get, just a when taking two parameters : the predicate and the mapping function. public class MatchMap { private final Optional opt; private final U defaultValue; private final AtomicReference result = new AtomicReference (); private MatchMap(Option…

You can simplify your code a little bit and add some wildcards :)

https://gist.github.com/anonymous/7d45e0f746b46684ec45

Re: Show HN: Motif – Scala-like pattern matching with Java 8

#18

Hard to read in comparison to Scala. It's impressive that it was accomplished but some things just aren't meant to happen in Java 8.

If you've ever endured the compilation time of a Scala codebase that has more than, say, 2000+ classes, then you might think that some things just aren't meant to happen in Scala either. I used Scala for 4+ years at a company that spent a non-trivial amount of time and resources speeding up its Scala builds (way more than 2000+ classes), sometimes doing sadly controversial things[1] to achieve that speedup. It was a…

Way more than 2000 classes? How many LOC is that?

How much time did it take to compile, and how much time does the same 2000+ classes take to compile in Java?

Re: Show HN: Motif – Scala-like pattern matching with Java 8

#19

Earlier quoted context omitted.

whoosh? http://www.scala-lang.org/

He said he wanted something that's not painful on the eyes.

I hardly see how Scala is more painful on the eyes than good old Java.

Re: Show HN: Motif – Scala-like pattern matching with Java 8

#20

Funny, I happened to code something just today very similar, but a lot lighter (just two classes, Match for consuming only, and MatchMap for mapping the optional. No when/get, just a when taking two parameters : the predicate and the mapping function. public class MatchMap { private final Optional opt; private final U defaultValue; private final AtomicReference result = new AtomicReference (); private MatchMap(Option…

You can simplify your code a little bit and add some wildcards :) https://gist.github.com/anonymous/7d45e0f746b46684ec45

Indeed, thanks!
Post reply on HN