0

In JavaFX's Property you can obtain a boolean binding for null or non null via val.isNull() and val.isNonNull().

What's the equivalence for this in ReactFX?

I've tried:

val.map(v -> v == null)

But it would return a Val<Boolean> with the actual value null instead of true (which is as expected in other cases).

Mordechai
  • 15,437
  • 2
  • 41
  • 82

1 Answers1

1

I think

val.map(v -> false).orElseConst(true)

will give you what you need.

James_D
  • 201,275
  • 16
  • 291
  • 322
  • Brilliant! But how come it's not baked into the api? – Mordechai Oct 26 '17 at 01:14
  • The use cases where you only care if it's null, but don't care what it's value is, are probably fairly rare. And since it's just one extra call (`orElseConst(true)`) on top of the `map`, it probably doesn't justify the additional API. Also, the general philosophy here is that `null` should represent "no value", rather than "a special value"; `orElse` and `orElseConst` are specifically there for the cases where you want to represent a "special value". – James_D Oct 26 '17 at 01:21
  • You can also look at it that `orElseConst` gives you both `isNull()` *and* `isNotNull()` (just reverse `true` and `false`), as well as lots of other useful functionality. So, again, the API trade off (API bloat vs convenience) is not worth it. – James_D Oct 26 '17 at 01:23