I want a method to update certain entries of an IEnumerable. I found that doing a foreach over the entries and updating the values failed as in the background I was cloning the collection. This was because my IEnumerable was backed by some LINQ->SQL queries.
By changing the method to take a List I have changed this behavior, Lists are a...
I have a Class that I need to copy with the ability to make changes the value of a variable on both Classes. Simply put these classes need to remain clones of each other at all times. My understanding of the documentation is that I can do this using a shallow copy of the Class which has also been declared mutable. By shallow copying the ...
Do they typically use non functional aspects of the language (including mutable variables).
Are there other strategies? Could you describe them?
...
I am hoping to redefine or update some bindings within a Module which is in turn used by an Injector. I realise that Modules are immutable and once a binding is sucked and injected its definition cannot change for all practical purposes.
I would like to add/change/remove bindings while keeping singletons already living in an Injector. ...
I'm pondering a current limitation of STL iterators and wondering if there's an elegant way around it. Here's my situation: I have a class that encapsulates a sequence container and a generic method to mutate the contents of the container, for example:
class Container {
typedef std::vector<int> Data;
Data data_;
public:
template ...
What is the best way to convert collection.immutable.Set to collection.mutable.Set?
...
First, I acknowledge the possibility that this question could be a duplicate; just let me know.
I'm curious what the general "best practice" is for those situations when mutability is desired. F# seems to offer two facilities for this: the let mutable binding, which seems to work like variables in "most" languages, and the reference cel...
So, I know you can't access variables outside scope, that they're immutable, that XSLT is functional not imperative, etc...
But I need a general purpose approach to something that would be trivial with global mutable variables (that sounds evil just saying it :). Here's an example...
<xsl:template match="t1">
<xsl:if test="someLogic"...
Using Scala 2.7.7, this works as expected:
import scala.collection.mutable.Stack
...
var x = new Stack[String]
x += "Hello"
println(x.top)
After changing to Scala 2.8.0, the += should be replaced by :+. However, this does not append to the stack: java.util.NoSuchElementException: head of empty list.
Am I overlooking something basic?
...
The following pattern has arisen in a program I'm writing. I hope it's not too contrived, but it manages to mutate a Foo object in the const method Foo::Questionable() const, without use of any const_cast or similar. Basically, Foo stores a reference to FooOwner and vice versa, and in Questionable(), Foo manages to modify itself in a c...
I have a bison grammar for collecting arguments of a function. This is what it is so far:
args: arg {$$ = intArray($1);} //pseudo-code function
| args arg {$$ = $1 + $2;} //pseudo-code array addition
arg : NUM {$$ = $1;}
| exp {$$ = $1;}
How can I create an array of inte...
Is it safe to modify a mutable object returned by a method of a standard library object?
Here's one specific example; but I'm looking for a general answer if possible.
#m is a MatchObject
#I know there's only one named group in the regex
#I want to retrieve the name and the value
g, v = m.groupdict().popitem()
#do something else with m...
How does a TreeSet, HashSet or LinkedHashSet behave when the objects are mutable? I cannot imagine that they would work in any sense?
If I modify an object after I have added it; what is the behaviour of the list?
Is there a better option for dealing with a collection of mutable objects (which I need to sort/index/etc) other than a lin...
I am loading a bitmap from a resource like so:
Bitmap mBackground = BitmapFactory.decodeResource(res,R.drawable.image);
What I want to do is make some changes to the bitmap before It gets drawn to the main canvas in my draw method (As it would seem wasteful to repeat lots of drawing in my main loop when it isn't going to change). I a...
I wrote a function very similar to this:
def writeMyEl (x: TypeA, y: TypeB, z : TypeC) {
if (myMutableHashMap.contains((x, y)))
myMutableHashMap(x, y) = z else
myMutableHashMap += (x, y) -> z
}
In real code Types A and B are enumerations ans C is a case class. myMutableHashMap is defined as a val of type scala.collectio...
I have an ivar which is alloc-inited in the init of an object:
attString = [[NSMutableAttributedString alloc] init];
On a loop, I want to clear the contents of attString and re-use it. How do I do this?
Thanks!
...
Update: It occurred to me after posting this question that the main downside of this idea would simply be that such a type would be easy to use improperly. That is, the type would have to be used in a very specific way to draw any benefits. What I originally had in mind was something that would be used like this (sticking with the Square...
A previous question with the same title as mine has been posted, with (I think) the same question, but had other problems in the code. I was not able to determine if that case was identical to mine or not.
Anyway, I want to replace an element within a list in a list.
Code:
myNestedList = [[0,0]]*4 # [[0, 0], [0, 0], [0, 0], [0, 0]]
myN...
Hello,
why or for what reason is it not possible to declare a class member variable in C++ as "static mutable"? Something like
static mutable int t; //This won't compile
For me, there is no reason to ban such declarations. E.g. for reasons like maintaining a global class-wide statistics, it may be convenient to have static variable t...
Simple problem: I am subclassing a FilterInputStream in Scala, which has a read method:
public void read(byte [] b,int offset,int len)
The data being read will be put in b, but as parameters are "vals" in Scala methods, I see no way to properly subclass this. How do I set b to the data being read? The Java *InputStream really leaves m...