falkreon / Jankson

JSON5 / HJSON parser and preprocessor which preserves ordering and comments
MIT License
51 stars 9 forks source link

Optional projections for collection elements #82

Closed falkreon closed 4 months ago

falkreon commented 5 months ago

Add enhanced versions of getObject / getArray / getPrimitive named tryGetObject / tryGetArray / tryGetPrimitive

For example, getObject produces an ObjectElement. tryGetObject would produce an Optional<ObjectElement>, so that short-circuiting substitution can be done.

Could also be covered using sneaky types so that an empty-projected ObjectElement could have asOptional() called on it and return EMPTY, or getObjectOr taking an object key and an object supplier. But I think tryGetObject and giving users access to the whole toolbox of Optional methods is the best value for the engineering effort.

falkreon commented 4 months ago

Completed with 00350736187ff761b194ad181f957a38859c59b5