MCPcopy Create free account
hub / github.com/cli/cli / Map

Function Map

pkg/option/option.go:140–146  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
140func 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}

Callers

nothing calls this directly

Calls 1

SomeFunction · 0.85

Tested by

no test coverage detected