• Knusper@feddit.de
    link
    fedilink
    arrow-up
    35
    arrow-down
    3
    ·
    9 months ago

    I enjoy this:

    return a.or(b);
    

    But yeah, that requires an Option type rather than null pointers…

    • mea_rah@lemmy.world
      link
      fedilink
      arrow-up
      6
      ·
      9 months ago

      Is that Rust? Assuming a is an Option (which would be close approximation of OP’s nullable type) and assuming b is not null, then this would be closer to the original idea:

      a.unwrap_or(b)
      

      It returns value of a if it’s not None rather than Option.