Skip to main content

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*.

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 ...
Marco Sulla's user avatar
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 ...
koussay issaoui's user avatar
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 ...
fluminis's user avatar
  • 196
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 ...
Gerard Torrent's user avatar
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'...
Mechanic Pig's user avatar
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 ...
Zymus's user avatar
  • 207
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 ...
StormCrow's user avatar
  • 369
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 ...
Neill's user avatar
  • 121
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, ...
ammut's user avatar
  • 161
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 ...
Benni's user avatar
  • 153
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 <...
kyun's user avatar
  • 121
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 ...
dfhwze's user avatar
  • 14.2k
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 ...
t3chb0t's user avatar
  • 44.7k
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 ...
S'pht'Kr's user avatar
  • 119
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: ...
coder_bro's user avatar
  • 419

15 30 50 per page
1
2 3 4 5 6