openlang

Obtaining an implicit context value

I'm exploring Kotlin's recent addition, Context parameters.

Under certain circumstances, a code block can have one or several contexts available without a direct way to reference them (there's no variable bound to them). They're accessible solely to forward into calls of functions taking context parameters.

What's the conventional way to retrieve one of these unnamed contexts?

I made this tiny utility to get at it:

context(current: C) inline fun <reified C> grabContext() = current

However, perhaps a standard function already does this.

The conversation continues 2

Follow the reasoning

Other sides of the same question

  1. How can I subclass a class inside another class?

    Hi, In a package whose code is outside my control, there is a hierarchy of classes arranged as follows: I'm trying to add a w…

    Replies 1Latest activity scala
  2. Comparing have with let bindings in Lean4

    I've observed that these two expressions and behave identically. This also happens in theorem proofs. Are they interchangeabl…

    Replies 3Latest activity lean-4
  3. TypeScript Map initialization with string array entries

    I'm creating a Map whose entries each hold an array of strings. How can I declare its type and initialize it together in one…

    Replies 2Latest activity typescript