immutability

Google Collections (Guava Libraries): ImmutableSet/List/Map and Filtering

最后都变了- 提交于 2019-12-19 17:47:21
问题 Assume that you want to build a copy of an ImmutableSet / List / Map object but filter out some of the original entries. One way to implement that is the following: ImmutableList.copyOf(Iterables.filter(myObject, myObject.EQUALS)); where myObject.EQUALS is a predicate for the Iterables.filter() operation. I think this is a pretty elegant and easy-to-read implementation. However, one builds two list objects (first through the Iterables.filter(...) call, second through ImmutableList.copyOf(...)

Google Collections (Guava Libraries): ImmutableSet/List/Map and Filtering

廉价感情. 提交于 2019-12-19 17:46:59
问题 Assume that you want to build a copy of an ImmutableSet / List / Map object but filter out some of the original entries. One way to implement that is the following: ImmutableList.copyOf(Iterables.filter(myObject, myObject.EQUALS)); where myObject.EQUALS is a predicate for the Iterables.filter() operation. I think this is a pretty elegant and easy-to-read implementation. However, one builds two list objects (first through the Iterables.filter(...) call, second through ImmutableList.copyOf(...)

Ruby - Immutable Objects

强颜欢笑 提交于 2019-12-19 17:32:33
问题 I've got a highly multithreaded app written in Ruby that shares a few instance variables. Writes to these variables are rare (1%) while reads are very common (99%). What is the best way (either in your opinion or in the idiomatic Ruby fashion) to ensure that these threads always see the most up-to-date values involved? Here's some ideas so far that I had (although I'd like your input before I overhaul this): Have a lock that most be used before reading or writing any of these variables (from

Moving objects across AppDomains in .NET

家住魔仙堡 提交于 2019-12-19 10:48:27
问题 Is there a way to efficiently share or move .NET objects across AppDomains? I realize that the intent of AppDomains is to provide isolation - however I have a case where I need to move a relatively large, cached set of immutable objects that are expensive to compute and create. At the moment, I have a serialization approach that works, but is rather slow. 回答1: You cannot move an object across an AppDomain without serializing it. That is the main point of an AppDomain - you can almost think of

Cheapest way of establishing happens-before with non-final field

风流意气都作罢 提交于 2019-12-19 09:07:17
问题 Many questions/answers have indicated that if a class object has a final field and no reference to it is exposed to any other thread during construction, then all threads are guaranteed to see the value written to the field once the constructor completes. They have also indicated that storing into a final field a reference to a mutable object which has never been accessed by outside threads will ensure that all mutations which have been made to the object prior to the store will be visible on

WebSQL: Are returned rows in SQLResultSetRowList immutable?

二次信任 提交于 2019-12-19 09:03:30
问题 I've been fetching rows from a WebSQL DB, and the returned rows seems to be readonly. db.readTransaction( function(t1) { t1.executeSql( "SELECT * FROM Foo WHERE id = ?", [1], function(t2, resultSet){ var foo = resultSet.rows.item(0); console.log("before: " + foo.col1); foo.col1 = "new value"; console.log("after: " + foo.col1); console.log("sealed? " + Object.isSealed(foo)); console.log("frozen? " + Object.isFrozen(foo)); } ); } ); It prints: before: old value after: old value sealed? false

Question about Scala variable Mutability

送分小仙女□ 提交于 2019-12-19 08:56:12
问题 I understand that val keyword determines the underlying variable is a Immutable type (Cannot be reassigned later time). Now i come across a paragraph in programming in scala (Chapter 3, Next steps in scala - parameterize arrays with types), it states val greetStrings: Array[String] = new Array[String](3) greetStrings(0) = "Hello" greetStrings(1) = ", " greetStrings(2) = "world!\n" These three lines of code illustrate an important concept to understand about Scala concerning the meaning of val

Are Delphi strings immutable?

十年热恋 提交于 2019-12-19 07:28:29
问题 As far as I know, strings are immutable in Delphi. I kind of understand that means if you do: string1 := 'Hello'; string1 := string1 + " World"; first string is destroyed and you get a reference to a new string "Hello World". But what happens if you have the same string in different places around your code? I have a string hash assigned for identifying several variables, so for example a "change" is identified by a hash value of the properties of that change. That way it's easy for me to

How can I modify a collection while also iterating over it?

限于喜欢 提交于 2019-12-19 02:54:24
问题 I have a Board (a.k.a. &mut Vec<Vec<Cell>> ) which I would like to update while iterating over it. The new value I want to update with is derived from a function which requires a &Vec<Vec<Cell>> to the collection I'm updating. I have tried several things: Use board.iter_mut().enumerate() and row.iter_mut().enumerate() so that I could update the cell in the innermost loop. Rust does not allow calling the next_gen function because it requires a &Vec<Vec<Cell>> and you cannot have a immutable

Immutable Hash and Array implementation in JavaScript?

↘锁芯ラ 提交于 2019-12-19 02:38:46
问题 Is there simple immutable hash and array implementation in javascript? I don't need best speed, a reasonable speed better than a clone would be good. Also, if there are simple implementations in Java or some other languages that can be easily understood and ported to JavaScript, it would be also nice. UPDATE: The goal isn't to just froze the hash (or array), but to make an efficient implementation of update operation - update of immutable hash should return a new immutable hash. And it should