fold<T> method

T fold<T>(
  1. T whenTrue,
  2. T whenFalse
)

Returns whenTrue if true, otherwise whenFalse.

A concise, chainable ternary for mapping a boolean to a value.

Example:

isDark.fold('dark', 'light'); // 'dark' when true

Implementation

T fold<T>(T whenTrue, T whenFalse) => this ? whenTrue : whenFalse;