Ticket #339 (assigned enhancement)
Provide a nil safe dereference operator
Reported by: | hopscc | Owned by: | Chuck |
---|---|---|---|
Priority: | medium | Milestone: | |
Component: | Cobra Compiler | Version: | 0.9.4 |
Keywords: | Cc: |
Description
Provide an operator that will allow deref through a chain of calls and member accesses even if something in the chain returns nil.
(nilsafe/elvis operator)
Like DOT operator but returns nil if prior element return nil
See Spaces around binary Ops
Preference for operator is ?. (QUESTION_DOT), Operation is analogous to DOT except that a nil ref short ccts and returns nil for the expression (chain).
# raw: name is nil or trimmed capitalized string name = customer?.name?.trim.capitalized # w/nilCoalesce: name is empty string or trimmed capitalized string name = customer?.name?.trim.capitalized ? ""
Should handle non idempotent calls/derefs.
If ambiguity between this and nil coalese op on trailing member ref then need space wrapped ops which should be done (if done) as a separate step.
Attachments
Change History
Note: See
TracTickets for help on using
tickets.