Language Design: Naming Conventions

Part 3: Options

Published on 2024-07-05.
Name Example
or Some(1).or(Some(2)) --> Some(1) None.or(Some(2)) --> Some(2)
orElse Some(1).orElse(2) --> Some(1) None.orElse(2) --> Some(2)
orGet Some(1).orGet(() -> Some(2)) --> Some(1) None.orGet(() -> Some(2)) --> Some(2) None.orGet(() -> None) --> None
orElseGet Some(1).orElseGet(() -> 2) --> Some(1) None.orElseGet(() -> 2) --> Some(2)
orElsePanic Some(1).orElsePanic() --> 1 None.orElsePanic() # program aborts
orElsePanicWith Some(1).orElsePanicWith("expected some") --> 1 None.orElsePanicWith("expected some") # program aborts with message "expected some"



Naming scheme:

  • ...Else... indicates going from Option[T] to T
  • ...Get indicates a closure argument
  • all panicking methods contain ...Panic