Wiki

Changes between Version 1 and Version 2 of NilableTypes

Show
Ignore:
Timestamp:
05/03/08 14:15:16 (17 years ago)
Author:
hopscc
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • NilableTypes

    v1 v2  
    4040}}}      
    4141 
    42 == nil and not nil detection and coalesce == 
     42== nil and not nil detection == 
    4343 
    4444You can explicitly test for nil or not nil values using normal conditionals ( true is non-nil) 
     
    5454}}} 
    5555 
    56 Nil test and assign or non nil test and process can be done using 'nil coalescing'[[BR]] 
     56== nil and non-nil coalesce == 
     57Shortcuts for Nil test and assign (coalesce) or non nil test and process [[BR]] 
    5758 
    58 '''?''' coalesce if nil.[[BR]] 
     59'''a ? b''' coalesce to b if (a) nil.[[BR]] 
     60The expression evaluates to a unless that value is nil, in which case, it evaluates to b.[[BR]] 
     61Neither expression will be evaluated more than once and if the first expression is non-nil then b will not be evaluated at all.[[BR]] 
     62( Also the direct augmented assignment version '''a ?= b'''   a gets b if a is nil ) 
    5963 
    60 '''! ''' execute if not nil.   
     64'''a !  b ''' evaluate b if a not nil.   
    6165{{{ 
    6266    stuff as String? = nil 
     
    6468  
    6569    stuff = stuff ? defaultStuff  # coalesce nil 
     70    # OR  stuff ?= defaultStuff 
    6671    # equivalent to  stuff = if (not stuff, defaultStuff, stuff) 
    6772    # or