Banjo

52 thoughts
last posted Nov. 9, 2015, 7:13 p.m.

16 earlier thoughts

0

Optional fields and parameters

One puzzle on my mind is how to handle methods/fields that may be missing. Functions may want to inspect an object and see whether it has certain fields or not, and perhaps check whether it conforms to some interface or structure.

I see this pattern often enough in Javascript that I'd like to have a simple syntax for it. Perhaps x.?y' to mean(hasattr(x, 'y') => some(x.y)) || none. Perhapsx?.?ywould meanx && x.?y`.

For a complex projection like x.{y,z}fields missing in the projected object could be considered missing in the resulting object, so if you try to access them with out using ?. you'd get a compile time error.

35 later thoughts