Better HN
topnewbestaskshowjobs
Log inSign up

johnlcox

38 karma · joined Nov 29, 2012 (14y ago) · 2 submissions

Submissions

comment 11y ago · link · parent

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.

2.

Show HN: Motif – Scala-like pattern matching with Java 8(github.com ↗)

51 points · by johnlcox · 11y ago · 34 comments