immutability

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

烂漫一生 提交于 2019-11-29 06:21: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

Immutable Scala Map implementation that preserves insertion order [duplicate]

匆匆过客 提交于 2019-11-29 05:24:05
This question already has an answer here: Scala Map implementation keeping entries in insertion order? 6 answers 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? ListMap implements an immutable map using a list-based data structure, and thus preserves insertion order. scala> import collection.immutable.ListMap import collection.immutable.ListMap scala> ListMap(1 -> 2) + (3 -> 4) res31: scala.collection.immutable.ListMap[Int,Int] = Map(1 -> 2, 3 -> 4) scala> res31 + (6 ->

Is there a corresponding immutable enumMap in guava?

醉酒当歌 提交于 2019-11-29 05:19:11
问题 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

Cocoa: Testing to find if an NSString is immutable or mutable?

空扰寡人 提交于 2019-11-29 04:26:47
This produces an immutable string object: NSString* myStringA = @"A"; //CORRECTED FROM: NSMutableString* myStringA = @"A"; This produces a mutable string object: NSMutableString* myStringB = [NSMutableString stringWithString:@"B"]; But both objects are reported as the same kind of object, "NSCFString": NSLog(@"myStringA is type: %@, myStringB is type: %@", [myStringA class], [myStringB class]); So what is distinguishing these objects internally, and how do I test for that, so that I can easily determine if a mystery string variable is immutable or mutable before doing something evil to it? The

Converting mutable to immutable map

安稳与你 提交于 2019-11-29 04:23:21
问题 private[this]object MMMap extends HashMap[A, Set[B]] with MultiMap[A, B] How convert it to immutable? 回答1: The immutable hierarchy doesn't contain a MultiMap, so you won't be able to use the converted structure with the same convenient syntax. But if you're happy to deal with key/valueset pairs, then: If you just want a mutable HashMap , you can just use x.toMap in 2.8 or collection.immutable.Map(x.toList: _*) in 2.7. But if you want the whole structure to be immutable--including the

final fields and thread-safety

最后都变了- 提交于 2019-11-29 04:23:11
Should it be all fields, including super-fields, of a purposively immutable java class 'final' in order to be thread-safe or is it enough to have no modifier methods? Suppose I have a POJO with non-final fields where all fields are type of some immutable class. This POJO has getters-setters, and a constructor wich sets some initial value. If I extend this POJO with knocking out modifier methods, thus making it immutable, will extension class be thread-safe? In order to use an effectively immutable object without final fields in a thread safe manner you need to use one of safe publication

The final word on NSStrings: Mutable and Immutable

杀马特。学长 韩版系。学妹 提交于 2019-11-29 04:18:52
I've read in several books... and online... about immutable and mutable strings. They claim "immutable strings" can't be changed. (But they never define "change".) Which of these NSStrings could be changed without using NSMutableString? The string contains "catfish"... and I later try to change it to "cat". (Same letters, just shorter.) It contains "cat"... and I try to change it to "catfish". (Similar start... but just made longer.) I change "cat" into "CAT". (Same letters, but just the case has changed.) I change "cat" into "dog". (Totally different string, but the same length.) I change

Efficient persistent data structures for relational database

喜你入骨 提交于 2019-11-29 03:16:36
问题 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.) 回答1: 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

Why is it okay that this struct is mutable? When are mutable structs acceptable?

ε祈祈猫儿з 提交于 2019-11-29 02:12:00
问题 Eric Lippert told me I should "try to always make value types immutable", so I figured I should try to always make value types immutable. But, I just found this internal mutable struct, System.Web.Util.SimpleBitVector32 , in the System.Web assembly, which makes me think that there must be a good reason for having a mutable struct. I'm guessing the reason that they did it this way is because it performed better under testing, and they kept it internal to discourage its misuse. However, that's

Complete List of immutable JDK classes?

我的未来我决定 提交于 2019-11-29 02:09:05
is there a list of de-facto immutable classes in the jdk? technically Immutable classes include the obvious Integer, Double etc.. de-facto immutable will include for example java.lang.String - it might technically be mutable but de-facto it is not. Also, are there Interfaces/Abstract classes which are required (as stated in the javadoc) to be immutable? if you cannot provide a complete List, i would already be happy if you know a bunch of classes which state immutability in its javadoc.. kavi temre I try to compile the list as much as I can: java.lang.String The wrapper classes for the