A type-indexed heterogeneous collection that stores values indexed by their types.
Context provides compile-time type safety for storing and retrieving values of different types. The phantom type parameter R tracks which types are present in the context, enabling the type system to verify that requested values exist.
Type parameters
- R
-
The phantom type representing the types stored in this context. Uses intersection types (A & B) to represent multiple stored types.
Attributes
- Companion
- object
- Source
- Context.scala
- Graph
-
- Supertypes
- Self type
-
Context[R]
Members list
Value members
Concrete methods
Combines this context with another, returning a new context containing all entries.
Combines this context with another, returning a new context containing all entries.
When both contexts contain the same type, the value from that (right) wins.
Type parameters
- R1
-
the type parameter of the other context
Value parameters
- that
-
the context to merge with
Attributes
- Returns
-
a new context containing entries from both
- Source
- Context.scala
Adds a value to this context, returning a new context with the expanded type.
Adds a value to this context, returning a new context with the expanded type.
If a value of the same type already exists, it is replaced.
Type parameters
- A
-
the type of the value to add
Value parameters
- a
-
the value to add (must not be null)
Attributes
- Returns
-
a new context containing the added value
- Throws
-
java.lang.NullPointerException
if
ais null - Source
- Context.scala
Retrieves the value of type A from this context.
Retrieves the value of type A from this context.
The type bound A >: R ensures at compile time that a value of type A (or a subtype) is present. Supertype lookups are supported: if you store a Dog and request an Animal, the Dog will be returned.
Type parameters
- A
-
the type to retrieve (must be a supertype of some type in R)
Attributes
- Returns
-
the stored value
- Throws
-
scala.NoSuchElementException
if no matching value is found (indicates a bug)
- Source
- Context.scala
Retrieves the value of type A if present, without requiring a type bound.
Retrieves the value of type A if present, without requiring a type bound.
Unlike get, this method does not require A to be in the context's type parameter. Use this for optional lookups where the type may or may not be present.
Type parameters
- A
-
the type to retrieve
Attributes
- Returns
-
Some(value) if found, None otherwise
- Source
- Context.scala
Returns true if this context contains no entries.
Returns true if this context contains at least one entry.
Narrows this context to contain only the specified types.
Narrows this context to contain only the specified types.
The type A should be an intersection of nominal types that are present in R. Any entries not in A are removed.
Type parameters
- A
-
the intersection type to keep (must be a supertype of R)
Attributes
- Returns
-
a new context containing only entries for types in A
- Source
- Context.scala
Returns the number of entries in this context.
Returns a string representation of the object.
Returns a string representation of the object.
The default representation is platform dependent.
Attributes
- Returns
-
a string representation of the object.
- Definition Classes
-
Any
- Source
- Context.scala
Transforms an existing value in this context.
Transforms an existing value in this context.
If the type is not present, the context is returned unchanged.
Type parameters
- A
-
the type to update (must be a supertype of some type in R)
Value parameters
- f
-
the transformation function (must not return null)
Attributes
- Returns
-
a new context with the transformed value
- Throws
-
java.lang.NullPointerException
if
freturns null - Source
- Context.scala