Skip to content

Member Accessor Operators

refractalize edited this page Feb 5, 2013 · 3 revisions

Normal Member Access

Normal member access is done with the dot . operator:

joe = {
    name = 'Joe'
}
joe.name == 'Joe'

Member Mapping

To map an array of objects to an array of their members, use the *. operator:

joe = {name = 'Joe'}
jenny = {name = 'Jenny'}
john = {name = 'John'}
contacts = [joe, jenny, john]
contacts*.name == ['Joe', 'John', 'Jenny']

Conditional Mapping

To return the member if the object is not nil, or otherwise to return nil, use the ?. operator:

joe = {name = 'Joe'}
nobody = nil

joe?.name == 'Joe'
nobody?.name == nil
Clone this wiki locally