immutability

Are immutable arrays possible in .NET?

五迷三道 提交于 2019-11-30 08:09:37
Is it possible to somehow mark a System.Array as immutable. When put behind a public-get/private-set they can't be added to, since it requires re-allocation and re-assignment, but a consumer can still set any subscript they wish: public class Immy { public string[] { get; private set; } } I thought the readonly keyword might do the trick, but no such luck. Ray Jezek ReadOnlyCollection<T> is probably what you are looking for. It doesn't have an Add() method. Quantenmechaniker The Framework Design Guidelines suggest returning a copy of the Array. That way, consumers can't change items from the

Immutable Scala Map implementation that preserves insertion order [duplicate]

懵懂的女人 提交于 2019-11-30 07:43:49
问题 This question already has answers here : Scala Map implementation keeping entries in insertion order? (6 answers) Closed 4 years ago . LinkedHashMap is used to preserve insertion order in the map, but this only works for mutable maps. Which is the immutable Map implementation that preserves insertion order? 回答1: ListMap implements an immutable map using a list-based data structure, and thus preserves insertion order. scala> import collection.immutable.ListMap import collection.immutable

Any weak interning collections (for immutable objects)

纵然是瞬间 提交于 2019-11-30 07:23:59
In some situations involving immutable objects, it will be possible for many distinct objects to come into existence which are semantically identical. A simple example would be reading many lines of text from a file into strings. From the program's perspective, the fact that two lines have the same sequence of characters would be "coincidence", but from the programmer's perspective a large amount of duplication may be expected. If many string instances are identical, changing the references to those distinct instances into references to a single instance will save memory, and will also

Functional Data Structures in Java

无人久伴 提交于 2019-11-30 07:07:19
Does the Java standard library have any functional data structures, like immutable Sets, Lists, etc., with functional update? Functional java has Sets, Lists and more interesting abstractions. Have a look at the pcollections project: PCollections serves as a persistent and immutable analogue of the Java Collections Framework. This includes efficient, thread-safe, generic, immutable, and persistent stacks, maps, vectors, sets, and bags, compatible with their Java Collections counterparts. Persistent and immutable datatypes are increasingly appreciated as a simple, design-friendly, concurrency

How does one use cached data in a functional language such as Erlang?

坚强是说给别人听的谎言 提交于 2019-11-30 06:40:13
I've been reading a bit lately about functional languages. Coming from 10+ years of OO development, I'm finding it difficult to get my head around how on earth one can point the pure functional approach (i.e. the same method called with the same parameters does the same thing) at a problem where typically (in an OO program) I would need to cache data. Do we just admit that there might need to be an actor in the program which is not immutable (i.e. the cache). I just watched a presentation by Joe Armstrong on infoq and he seemed pretty dogmatic in this regard! Do we just admit that looking up

Is there a corresponding immutable enumMap in guava?

天涯浪子 提交于 2019-11-30 06:02:19
I recently learnt about the benefits of EnumMap in Java and would like to replace the existing ImmutableMap<OccupancyType, BigDecimal> to EnumMap. However, I'd also like the immutable property offered by ImmutableMap. Is there a variant, ImmutableEnumMap available in guava ? In terms of storage which one (EnumMap vs ImmutableMap) performs better ? I couldn't find a comparison of the two. I'd appreciate if someone can point me to a link or give some insights on the efficiency of the two data structures ? Louis Wasserman Guava contributor here. Guava doesn't currently have an ImmutableEnumMap

Efficient persistent data structures for relational database

主宰稳场 提交于 2019-11-30 05:18:34
I'm looking for material on persistent data structures that can be used to implement a relational model. Persistence in the meaning of immutable data structures. Anyone know of some good resources, books, papers and such? (I already have the book Purely Functional Data Structures , which is a good example of what I'm looking for.) It is straightforward to modify the ubiquitous B-tree to be persistent. Simply always alloctate a new node whenever a node is modified, and return the new node to the recursive caller, who will insert it at that level by allocating a new node, etc. Ultimate the new

Why is PostgreSQL calling my STABLE/IMMUTABLE function multiple times?

夙愿已清 提交于 2019-11-30 04:53:57
I'm trying to optimise a complex query in PostgreSQL 9.1.2, which calls some functions. These functions are marked STABLE or IMMUTABLE and are called several times with the same arguments in the query. I assumed PostgreSQL would be smart enough to only call them once for each set of inputs - after all, that's the point of STABLE and IMMUTABLE, isn't it? But it appears that the functions are being called multiple times. I wrote a simple function to test this, which confirms it: CREATE OR REPLACE FUNCTION test_multi_calls1(one integer) RETURNS integer AS $BODY$ BEGIN RAISE NOTICE 'Called with %'

Why Wrapper class like Boolean in java is immutable?

这一生的挚爱 提交于 2019-11-30 04:44:03
问题 I can't see the reason why the Boolean wrapper classes were made Immutable. Why the Boolean Wrapper was not implemented like MutableBoolean in Commons lang which actually can be reset. Does anyone have any idea/understanding about this ? Thanks. 回答1: Because 2 is 2. It won't be 3 tomorrow. Immutable is always preferred as the default, especially in multithreaded situations, and it makes for easier to read and more maintainable code. Case in point: the Java Date API, which is riddled with

Immutable views of mutable types

醉酒当歌 提交于 2019-11-30 04:33:13
问题 I have a project where I need to construct a fair amount of configuration data before I can execute a process. During the configuration stage, it's very convenient to have the data as mutable. However, once configuration has been completed, I'd like to pass an immutable view of that data to the functional process, as that process will rely on configuration immutability for many of its computations (for instance, the ability to pre-compute things based on initial configuration.) I've come up