Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [covariance]

Covariance, contravariance and invariance describe how the existing type inheritance hierarchy changes when subjected to some transformation (such as usage within generics). If the transformation keeps the ordering of the original hierarchy, it is "covariant". If it reverses it, it is "contravariant". If it breaks it, it is "invariant".

Filter by
Sorted by
Tagged with
10 votes
3 answers

Filter out nulls from sequence of nullables to produce sequence of non-nullables

While introducing nullable reference types to our enterprise application's codebase, I found that we are often using LINQ on sequences of nullable reference types where we filter out the nulls using <...
4 votes
1 answer

C++ covariant_invoke

This utility function invokes one of a list of functions which are covariant on the provided value. It reduces boilerplate by internally performing dynamic_cast on the input value, and invokes the ...
2 votes
0 answers

Imitate Qt Quick's QQuickFramebufferObject, but do the syncing more tidily (with covariance)

I'm making a system similar to Qt Quick with its scenegraph. Since it's embedded within Qt Quick with its threading system, the items' Renderers should sync some ...
10 votes
1 answer

A Covariant Tuple

I was searching for a way to put a Tuple<List> into a Tuple<IEnumerable>, and I found that Tuple has no covariance. ...
5 votes
3 answers

"fake" covariance in PHP type-hinting

Here's the situation: I've got several distinct objects, each with their own responsability and (therefore) each their own dependencies. As this is code that will be implemented in 2 existing ...
3 votes
2 answers

Sequential Execution: Orchestrator Pattern

I built a code piece that makes it easy to execute a set of sequential operations, that might depend on the same parameter value (passed across the execution) or might need a particular parameter. ...