immutability Questions

6

Solved

In Rust, you don't specify mutability inside a struct, but it is inherited from the variable binding. That's great, but is it possible to force a field to be always immutable, even when the root is...
Selfabnegation asked 19/5, 2014 at 17:16

3

Solved

It is possible to coerce &mut T into &T but it doesn't work if the type mismatch happens within a type constructor. playground use ndarray::*; // 0.13.0 fn print(a: &ArrayView1<i3...
Taritariff asked 12/4, 2020 at 15:32

6

Solved

I'm looking for a way to freeze native ES6 Maps. Object.freeze and Object.seal don't seem to work: let myMap = new Map([["key1", "value1"]]); // Map { 'key1' => 'value1' } Object.freeze(myMap...
Izolaiztaccihuatl asked 2/3, 2016 at 12:30

20

Solved

I am unable to get what are the scenarios where we need an immutable class. Have you ever faced any such requirement? or can you please give us any real example where we should use this pattern.
Classicize asked 22/9, 2010 at 13:17

4

Solved

I have been playing around with dataclasses dynamically loaded with property names from a file and I am unable to find a way to create both 'frozen' and 'non-frozen' properties. I believe dataclass...
Stinko asked 23/10, 2019 at 23:58

2

Solved

TypeScript defines ReadonlyMap<K, V> interface which is immutable version of standard JavaScript Map<K, V> type. How are we supposed to use ReadonlyMap<K, V> in our code? It's n...
Concavity asked 26/4, 2018 at 15:15

10

Solved

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 st...
Stpeter asked 16/10, 2008 at 21:49

5

I have an array of objects. I would like to deep copy the array of objects and make some changes to each object. I want to do this without modifying the original array or original objects that were...
Harrisharrisburg asked 4/8, 2017 at 17:46

0

I'll try to describe the problem with a short example. Lets assume we have a child composable representing a custom switch, and we want to keep it immutable, so we need to pass the initial state an...
Tannertannery asked 17/8, 2022 at 11:59

4

I have a freezed class in flutter as follows: @freezed abstract class Data with _$Data { const factory Data({ String id, String name, String parentId,//null if it is the root element @Default...
Cud asked 11/6, 2020 at 15:0

7

Solved

What are the design reasons of making Python strings immutable? How does it make programming easier? I'm used to mutable strings, like the ones in C. How am I supposed to program without mutable s...
At asked 30/12, 2011 at 13:45

6

I was just going through mutable and immutable structures in python. It was written that "Strings are immutable" in Python i.e We cannot alter them Consider the code: str1='Rohit' str1.replace('R'...
Edgington asked 14/11, 2017 at 14:0

4

Strings in Python are immutable, which means the value cannot be changed. However, when appending to the string in the following example, it looks like the original string memory is modified since ...

7

Solved

Strategy for defining immutable class says that all the fields should be final. For ex: private String name; Why does it have to be final? Since I am not giving setter methods for it? It can'...
Granulate asked 4/9, 2013 at 7:32

4

Solved

Is it possible to define an immutable struct in Golang? Once initialized then only read operation on struct's field, no modification of field values. If so, how to do that.
Charpentier asked 4/12, 2017 at 11:48

3

Solved

I have a situation where I have a process which needs to "burn-in". This means that I Start with p values, p relatively small For n>p, generate nth value using most recently generated...
Brandonbrandt asked 10/5, 2022 at 9:47

10

Solved

If a string is immutable, does that mean that.... (let's assume JavaScript) var str = 'foo'; alert(str.substr(1)); // oo alert(str); // foo Does it mean, when calling methods on a string, it w...
Broadbill asked 8/7, 2010 at 1:54

9

Solved

How can the following operation be done without mutating the array: let array = ['item1']; console.log(array); // ['item1'] array[2] = 'item2'; // array is mutated console.log(array); // ['item1',...
Housley asked 27/6, 2016 at 18:23

3

Solved

So I have some pretty extensive functional code where the main data type is immutable structs/classes. The way I have been declaring immutability is "practically immutable" by making member variabl...
Manicdepressive asked 11/11, 2014 at 5:59

1

Solved

Does writing programs with immutable objects cause performance problems? If a given object is immutable and we need to somehow change its state, we have to map it to a new object with a slightly ch...
Siesta asked 13/3, 2022 at 9:15

5

Following comes from React tutorial: const squares = this.state.squares.slice(); squares[i] = 'X'; this.setState({squares: squares}); This code changes copied state.squares and assign it to orgi...

3

Solved

Are Strings mutable in Ruby? According to the documentation doing str = "hello" str = str + " world" creates a new string object with the value "hello world" but when we do str = "hello" str ...
Socinus asked 16/4, 2011 at 12:53

2

We're currently using Guava for its immutable collections but I was surprised to find that their maps don't have methods to easily create new maps with minor modifications. And on top of that, thei...
Reactive asked 1/2, 2012 at 5:55

4

Solved

I'm working with a struct which has an array. I would like to add a new element to the array, however, the array is immutable so I can't simply append to it. Need to create a new array, append to i...
Walkon asked 26/5, 2016 at 6:25

3

Solved

I couldn't find an answer in both stackoverflow and the Julia docs to the following "design problem": Let's say I want to define the following object struct Person birthplace::String age::Int end...
Heterogamete asked 23/1, 2018 at 12:5

© 2022 - 2024 — McMap. All rights reserved.