Questions tagged [mutable]

A mutable can be modified after it is created.

A mutable can be modified after it is created. It is a keyword in functional programming opposite to immutable.

Related tags:

1184 questions
20
votes
2 answers

scala append to a mutable LinkedList

Please check this import scala.collection.mutable.LinkedList var l = new LinkedList[String] l append LinkedList("abc", "asd") println(l) // prints // LinkedList() but import scala.collection.mutable.LinkedList var l = new…
weima
  • 4,653
  • 6
  • 34
  • 55
19
votes
3 answers

Kotlin: val mutableList vs var immutableList. When to use which?

We are encouraged to have immutable variables as much as we can. But sometimes when I have to modify a list I start to wonder which approach would be better for current situation... val mutableList = mutableListOf() // where I can just .add() /…
Elye
  • 53,639
  • 54
  • 212
  • 474
19
votes
10 answers

Set Collection for mutable objects in Java

In Java, a set only checks for equality of an object with objects already in the set only at insertion time. That means that if after an object is already present in the set, it becomes equal to another object in the set, the set will keep both…
Jadiel de Armas
  • 8,405
  • 7
  • 46
  • 62
19
votes
5 answers

Haskell mutable map/tree

I am looking for a mutable (balanced) tree/map/hash table in Haskell or a way how to simulate it inside a function. I.e. when I call the same function several times, the structure is preserved. So far I have tried Data.HashTable (which is OK, but…
ondra
  • 9,122
  • 1
  • 25
  • 34
19
votes
3 answers

Two dimensional vectors in Rust

Editor's note: This question predates Rust 0.1 (tagged 2013-07-03) and is not syntactically valid Rust 1.0 code. Answers may still contain valuable information. Does anyone know how to create mutable two-dimensional vectors in Rust and pass them…
php--
  • 2,647
  • 4
  • 16
  • 18
18
votes
4 answers

What is the theory behind mutable and immutable types?

One of the things that I admire about Python is its distinction between mutable and immutable types. Having spent a while programming in c before coming to Python, I was astonished at how easily Python does away with all the complexities of pointer…
jsau
  • 837
  • 7
  • 11
18
votes
2 answers

When is it okay to use "var" in Scala?

I know that Scala has var (for mutable state) but pure functional programming discourages use of any mutable state and rather focuses on using val for everything. Coming from an imperative world it's hard to let go of mutable state. My question is…
Soumya Simanta
  • 11,523
  • 24
  • 106
  • 161
17
votes
3 answers

Why are System.Windows.Point & System.Windows.Vector mutable?

Given that mutable structs are generally regarded as evil (e.g., Why are mutable structs “evil”?), are there potential benefits that might have prompted the designers of the .NET framework to make System.Windows.Point & System.Windows.Vector…
devuxer
  • 41,681
  • 47
  • 180
  • 292
17
votes
1 answer

Rust mutable value vs mutable reference

What is the difference between let y = &mut 5; *y += 1; let x = *y + 1; and let mut y = 5; y += 1; let x = y + 1; They return the same result via println!, but I can't decide which one is preferable.
tbmale
  • 185
  • 1
  • 1
  • 5
17
votes
3 answers

Is an immutable Bitmap faster then a mutable one?

The Bitmap class has a method copy() with the signature below: public Bitmap copy(Bitmap.Config config, boolean isMutable) Is there a performance difference between a mutable and an immutable Bitmap?
Adam Stelmaszczyk
  • 19,665
  • 4
  • 70
  • 110
16
votes
3 answers

Java Mutable BigInteger Class

I am doing calculations with BigIntegers that uses a loop that calls multiply() about 100 billion times, and the new object creation from the BigInteger is making it very slow. I was hoping somebody had written or found a MutableBigInteger class. I…
Fractaly
  • 834
  • 2
  • 10
  • 25
16
votes
4 answers

Android mutable bitmap

Can someone please explain to me what a mutable bitmap is? What advantages/disadvantages or what limitations do mutable and immutable bitmaps have?
Buda Gavril
  • 21,409
  • 40
  • 127
  • 196
16
votes
8 answers

Correct alternative to a 'mutable function' in c++

I often have a problem with const correctness when wrapping algorithms in classes in c++. I feel that I want a mutable function, although this is not allowed. Can anyone advise me how to implement classes such as the one that follows? The…
Tom
  • 5,219
  • 2
  • 29
  • 45
16
votes
1 answer

Python: Replacing an element in a list of lists (#2)

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…
Richard
  • 163
  • 1
  • 4
16
votes
1 answer

How do I pass a mutable vector as a function parameter in Rust?

I am implementing a small program that evaluates the Collatz conjecture. As part of this, I have a function that I call recursively that I want to store the current number being evaluated, determine if it is a odd or even (or terminate if it's just…
mer219
  • 163
  • 1
  • 1
  • 6