Immutable type and property in C#

An immutable type is a type of which its properties can only be set at initialization. Once an object is created, nothing can be changed anymore. An immutable property is simply a read-only property. In the following example, ImmutableType is an immutable type with one property Test. Test is a read-only property. It can only … Read more

How to create an immutable map/set from a seq?

In Scala 2.8: Welcome to Scala version 2.8.0.r20327-b20091230020149 (Java HotSpot(TM) Client VM, Java 1.6. Type in expressions to have them evaluated. Type :help for more information. scala> val seq: Seq[(String,Object)] = (“a”,”A”)::(“b”,”B”)::Nil seq: Seq[(String, java.lang.Object)] = List((a,A), (b,B)) scala> val map = Map(seq: _*) map: scala.collection.immutable.Map[String,java.lang.Object] = Map(a -> A, b -> B) scala> val … Read more

Difference between MappingProxyType and PEP 416 frozendict

TL;DR MappingProxyType is a read only proxy for mapping (e.g. dict) objects. frozendict is an immutable dict Answer The proxy pattern is (quoting wikipedia): A proxy, in its most general form, is a class functioning as an interface to something else. The MappingProxyType is just a simple proxy (i.e. interface) to access the real object … Read more

TypeScript return immutable/const/readonly Array

This seems to work… function getList(): ReadonlyArray<number> { return [1, 2, 3]; } const list = getList(); list[0] = 3; // Index signature in type ‘ReadonlyArray<number>’ only permits reading. Try it in the Playground ReadonlyArray<T> is implemented like this: interface ReadonlyArray<T> { readonly [n: number]: T; // Rest of the interface removed for brevity. }

tech