Skip to content

Commit

Permalink
Merge pull request #909 from NthPortal/sdk-Context-getOrElse
Browse files Browse the repository at this point in the history
Add `sdk.Context#getOrElse`
  • Loading branch information
iRevive authored Feb 5, 2025
2 parents 4450fc0 + 0cc562c commit a04dd8f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private[sdk] object SdkBaggageManager {
.unsafeRunSync()

private def baggageFromContext(context: Context): Baggage =
context.get(BaggageKey).getOrElse(Baggage.empty)
context.getOrElse(BaggageKey, Baggage.empty)

def fromLocal[F[_]: LocalContext]: BaggageManager[F] =
new SdkBaggageManager[F]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ sealed trait Context {
*/
def get[A](key: Context.Key[A]): Option[A]

/** Retrieves the value associated with the given key from the context, if such a value exists; otherwise, returns the
* provided default value.
*/
def getOrElse[A](key: Context.Key[A], default: => A): A =
get(key).getOrElse(default)

/** Creates a copy of this context with the given `value` associated with the given `key`.
*/
def updated[A](key: Context.Key[A], value: A): Context
Expand Down

0 comments on commit a04dd8f

Please sign in to comment.