generic-variance Questions

2

Solved

Could you please explain using small and simple TypeScript examples what is Variance, Covariance, Contravariance, Bivariance and Invariance?

2

Solved

Recently I ran into a problem where I had a function which had to return an Array of Is, in form of all values of enum E, with E implementing interface I, with every code that came to my mind compi...
Breathtaking asked 15/1, 2019 at 14:27

1

I've been recently learning Kotlin, while having some questions with covariant type. The sample code is here. I have Option and Option2 both having a type parameter T and a run extension. I coul...
Kopans asked 19/4, 2019 at 16:50

2

Solved

I'm new to Kotlin. When I learn Storing Properties in a Map. I try following usage. class User(val map: MutableMap<String, String>) { val name: String by map } class User(val map: Mutab...
Arginine asked 21/6, 2017 at 1:27

1

Solved

In the following sample, I can pass a Consumer<Optional<Integer> to foo, but not a Consumer<Optional<Number>>. On the other hand, I can pass either type to foo2, but then I can...
Ballonet asked 30/6, 2017 at 8:3

1

Solved

In coursera functional programming course, I came across a subtle concept. If A2 <: A1 and B1 <: B2, then (A1 => B1) <: (A2 => B2) Justification when we pass an argument to A2 and beca...
Lyallpur asked 12/12, 2016 at 9:52

3

Solved

The following raises complaints: interface IInvariant<TInv> {} interface ICovariant<out TCov> { IInvariant<TCov> M(); // The covariant type parameter `TCov' // must be invarian...
Connective asked 17/5, 2016 at 14:27

3

Solved

Assume I have an interface such as public interface IInterface<in TIn, out TOut> { IInterface<TIn, TOut> DoSomething(TIn input); } TIn being contra-variant, and TOut being co-varian...
Sitter asked 18/2, 2016 at 11:51

2

Solved

Take this small LINQPad example: void Main() { Foo<object> foo = new Foo<string>(); Console.WriteLine(foo.Get()); } class Foo<out T> { public T Get() { return default...
Declaim asked 20/3, 2015 at 13:37

2

Solved

The codes below are exactly the same, except that one is C# and the other one is VB.Net. C# compiles just fine, but VB.Net throws the warning: Interface 'System.IObserver(Of Foo)' is ambiguous w...
Copro asked 27/12, 2011 at 18:2

2

Solved

Currently I'm preparing a presentation of the new generic variance features in C# for my colleagues. To cut the story short I wrote following lines: IList<Form> formsList = new List<Form&...
Tabbie asked 26/10, 2011 at 18:45

3

Solved

First, sorry for the vague question title. I couldn't come up with a more precise one. Given these types: { TCommand : ICommand } «interface» «interface» / +-----------+ +--------------------...
Cecilycecity asked 10/8, 2011 at 11:43

1

Solved

Inspired by Real-world examples of co- and contravariance in Scala I thought a better question would be: When designing a library, are there a specific set of questions you should ask yourself whe...
Candelabrum asked 11/3, 2011 at 23:34

2

Solved

I didn't attend PDC 2008, but I heard some news that C# 4.0 is announced to support Generic covariance and contra-variance. That is, List<string> can be assigned to List<object>. How co...
Relations asked 29/10, 2008 at 2:27

3

Solved

Generic Variance in C# 4.0 has been implemented in such a way that it's possible to write the following without an exception (which is what would happen in C# 3.0): List<int> intList = new ...
1

© 2022 - 2024 — McMap. All rights reserved.