- Scala allows to match more special objects by more general cases:
Some(1) match { case o: Option[Int] => true } // = true
- Scala also allows to match more general objects by more special cases:
val o: Option[Int] = Some(1)
o match { case Some(1) => true } // = true
Both cases are supported by Javaslang:
Ad 1)
// Match as Monad
Match.of(new Some<>(1))
.whenApplicable((Option<Integer> i) -> true).thenApply()
.get(); // = true
Match.of(new Some<>(1))
.whenType(Option.class).then(true)
.get(); // = true
// Match as Function
Match.whenApplicable((Option<Integer> i) -> true).thenApply()
.apply(new Some<>(1)); // = true
Match.whenType(Option.class).then(true)
.apply(new Some<>(1)); // = true
Ad 2)
// Match as Monad
Match.of(Option.of(1))
.whenIs(new Some<>(1)).then(true)
.get(); // = true
// Match as Function
Match.whenIs(new Some<>(1)).then(true)
.apply(Option.of(1)); // = true