Questions tagged [immutability]
Immutability is the inability to modify data after it has been created. Modifications are instead made by copying the data. A property of immutable data is that it is *referentially transparent*.
80 questions
6
votes
1
answer
922
views
Python function that deeply "freezes" an object
I implemented a function that gets an object and returns its immutable counterpart. If the object contains another mutable object at any level, it freezes it too.
Is my code is good and/or can it be ...
5
votes
1
answer
386
views
Trying Out DDD : How to enforce data integrity and immutability
I've been transitioning from type-safe programming languages like Dart and Java to Python, and I'm trying to enforce Domain-Driven Design (DDD) principles in a language that naturally leans towards ...
4
votes
1
answer
135
views
Lift simulator in Java
I implement a working version of the Lift Kata
Can you provide me some tips to improve my code?
I am not very proud of the handleLiftWithOpenDoors method that have ...
5
votes
4
answers
804
views
An immutable C++ string with ref-counting
Class intended to be used as main type in a key-value database where keys and values are strings. Searched features:
It is a const char *
Behaves like a ...
3
votes
1
answer
272
views
Implement a Python frozenmap
There are frozenset in Python, but no frozendict or frozenmap. I tried to implement it (Don'...
3
votes
0
answers
163
views
Replacing type-check with Visitor in Immutable Event-Sourced Aggregate
In my previous question, one of the answers mentioned that I shouldn't be changing behavior based on the Event class
The whole point of classing is that you can get result without having to decide ...
2
votes
1
answer
131
views
Immutable interpreter in C++
I am writing an immutable interpreter in C++ for fun. Originally standard vectors and dequeues were used to create a double ended queue data type, but it was very slow, because each operation require ...
2
votes
0
answers
201
views
Project Euler #14: Longest Collatz sequence on HackerRank
The following is the conclusion in a long chain of attempts to solve Project Euler problem #14 (Longest Collatz sequence) on HackerRank in the Haskell programming language.
The problem is defined as ...
2
votes
1
answer
356
views
A new CHAMPion - Compressed Hash-Array Mapped Prefix-tree in C
I implemented an immutable hash map in C, as described in this paper. First, my design goals:
plug-and-playable: compile with gcc -O3 -std=c11 champ.c, ...
2
votes
0
answers
75
views
Immutable-Object-like Structure in PHP
I made a closure-based PHP structure that behaves mostly like a classical object.
To change the object's state, one must derive a new copy by passing the altered state to the ...
2
votes
0
answers
35
views
Set values with keeping immutability in React FC
I'd like to know there's a better code than I did.
interface AnswerProps{
itemId: string;
value: Array<string>
}
This code works like checkbox. If <...
4
votes
1
answer
148
views
Immutable Keyed Set
Description
An immutable keyed set is a readonly collection of elements without
duplicates or null values having each of the elements linked to
exactly one key.
Example
This simple example of ...
8
votes
2
answers
389
views
Immutable builder and updater
There aren't enough questions about creating immutable objects... so why not try it again with another approach. This time, it's a builder that maps properties to constructor parameters. Properties ...
1
vote
1
answer
2k
views
Builder pattern in C# supporting subclassing with nested classes [closed]
[Posted yesterday on Software Engineering, but was apparently "disappeared"...maybe better here]
Background: I am just starting to get my head around the idea of separating the domain model from the ...
7
votes
1
answer
239
views
Quicksort in JavaScript assuming an immutable array
Update: further succinct versions below (inspired by Haskell)
Quick sort in JS assuming an immutable array:
...