Map applies a function to the contained value of (if [Some]), or returns [None]. Use this function very sparingly as it can lead to very unidiomatic and surprising Go code. However, there are times when used judiciiously, it is significantly more ergonomic than unwrapping the Option.
(o Option[T], f func(T) U)
| 138 | // Use this function very sparingly as it can lead to very unidiomatic and surprising Go code. However, |
| 139 | // there are times when used judiciiously, it is significantly more ergonomic than unwrapping the Option. |
| 140 | func Map[T, U any](o Option[T], f func(T) U) Option[U] { |
| 141 | if o.present { |
| 142 | return Some(f(o.value)) |
| 143 | } |
| 144 | |
| 145 | return None[U]() |
| 146 | } |