Covariance of immutable containers
See original GitHub issueHello! I’ve just started to use Language.Ext.Core
and I’ve ran into the small inconvenience - Either<L, R>
(like all other container types in this library) is not covariant on its type arguments. In some cases it forces me to cast returned value manually to the base class. Does this design have some purpose? If I understand everything correctly we can make immutable containers covariant essentially for free. But maybe I’ve missed something important…
Thank you in advance.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Immutability and Co/Contravariance - Nami's Tech Blog
There are many reasons to use immutable data structures and you ... Lists (and other containers) not being covariant makes our lives hard....
Read more >Covariance, Contravariance, and Invariance
In Python, most immutable containers are covariant. Tuples and frozensets (their type is FrozenSet ) are the most significant ones.
Read more >Why doesn't C++ support covariance in STL containers like ...
So, the reason, STL containers are not covariant, is because C++ doesn't support that. Note that std::vector is mutable, so it cannot be ......
Read more >Returning immutable.Map with covariant type - scala
I have a Container type that is covariant on its type parameter. class Container[+T](val map: Map[Int, T] ...
Read more >Immutable Interfaces and Covariant Return Types in Java
Today, let's look at a simple example which shows how the Immutable Interface pattern and also covariant return types can help you write ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Hinidu Indeed it’s sometimes a little ugly I’m afraid. To reduce the amount of clutter from casting I tend to use the
as
operator (even if it’s slightly less efficient):Or you could use
MapLeft
if you want to be more declarative:@louthy Thank you for suggestions 👍