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
2answers
76 views
Coin Change Kata in Immutable JS
I'm preparing for a job as a junior/intermediate JS developer. I'm comfortable with my ability to think in higher-order functions, but less confident in my syntax and style. (I have more experience in ...
3
votes
1answer
86 views
Functional API wrapper written in Scala
I've been working on an small API wrapper for the GitHub API using Scala (full source on GitHub). I'm still very new to the language, so I was hoping to get some feedback about a couple of design ...
1
vote
1answer
49 views
Non-persistent storage for key-value pairs
I got an interesting interview question related to JavaScript:
In JAVASCRIPT please create a storing function called storingFn with the following characteristics:...
6
votes
2answers
186 views
Generic immutable object builder
I've made an object builder which can create all sorts of classes, it can also create immutable objects.
There are 2 requirements that must be met in order for this pattern to work with fully ...
2
votes
1answer
56 views
Immutable ES7 global state store
I am quite an experienced developer but I am quite new to JS/frontend/functional programming and I am working with react-native in my day-job now.
I'm trying to do my own flux implementation to ...
12
votes
1answer
285 views
Cat fight (with rockets)
My code is attempting to implement FP in an efficient / readable manner into some of my video games. I realize this may be a bit subjective, but I feel there is enough merit / objectivity to be of ...
3
votes
1answer
99 views
Subclassing `int` to make colors
In the ROOT framework (originally a C++ framework, but python bindings are also supplied), colors are objects (ROOT.TColor) identified with an integer index.
This ...
6
votes
2answers
149 views
Implementation of a Location object, to be used in building a text-based adventure game
Based on responses to my question posted here, I've built a full implementation of a Location object. Such an object can be used to build a map for a text-based adventure game.
Feel free to review ...
2
votes
2answers
100 views
A Scala Maze Generator in Functional Style
I'm wondering if there is more I can do to incorporate more idiomatic scala and functional programming principles. I know the maze itself is mutable but i didn't see an easy solution to making it ...
2
votes
1answer
52 views
Building and querying an immutable phone book
I wanted to get your opinion on this immutable implementation of a Phone Book using recursion to process a stream. I am especially interested in ways to speed up the code execution.
Here is an ...
0
votes
1answer
40 views
Class that holds calculation results and has to be immutable
I'm roughly trying to follow the guidelines in "Effective Java", "Item 15: Minimize mutability", hence the class is not "final" on purpose.
Information is gathered from a number of temperature ...
8
votes
1answer
83 views
TCPListener server to discover clients on a network
I am currently writing a program to sync files (music, photos, etc) from my PC to an Android device. In order to do this, I have 2 application: one that is running on my PC, and one that shall be ...
4
votes
1answer
47 views
Immutable File Upload Server Configuration Class (FTP or Network Drive)
The application I'm working on needs to occasionally take pictures, and then send them to either an ftp server or a network drive (user configurable). To try to abstract away the differences between a ...
7
votes
3answers
335 views
Initializing immutable objects with a nested builder
I need to initialize several parameters of an object but I also wanted to make it immutable. At the same time I don't want the constructor to take all several parameters because some of them are ...
0
votes
2answers
526 views
Returning a byte array from a method [closed]
public abstract class Element
{
// Removed for verbosity ...
protected abstract byte[] GetBytes();
}
I'm attempting to create an engine that can create a ...
5
votes
4answers
2k views
Simple builder pattern implementation for building immutable objects
This is a builder pattern implementation to build immutable Person objects:
Person class
...
5
votes
1answer
199 views
Yet another immutable string
I know, there are a few implementations of immutable strings out there, but my focus seems to be a little different.
My goal was to have a type that provided value semantics, but didn't incur the ...
3
votes
5answers
142 views
An immutable person
I am trying to model person in OOPS using immutability.
I have created an object bond with age as 25. To change the age I have created a new object and returned it.
...
8
votes
2answers
405 views
Declaration of bloatedness: the class that knew too much?
I've already expressed concerns about this type's constructor, and I've sort-of* implemented the changes suggested in the answers I got there.
Recently I added even more parameters to that ...
2
votes
2answers
110 views
Immutable subclass of a Set class
If I'm creating an immutable class from an existing class, should I override methods that mutate the property or have an instance of it and write my own methods to read from the property?
I have an ...
1
vote
1answer
278 views
Immutable C++ String class
I have project where I will need to create lots of immutable strings. If I am using std::string, which has huge overhead - about 60-70% against ...
6
votes
4answers
155 views
7
votes
3answers
644 views
8
votes
4answers
1k views
Creating unique registration numbers using object factories
I'm learning about immutability and uniqueness in Java, particularly the use of defensive programming and object factories.
I have been asked to create a class containing an object factory that when ...
5
votes
2answers
614 views
Functions with mutable and non-mutable named tuples
I am making some functions within a function for learning which when passed information about a named tuple: it returns a reference to a class object from which we can construct instances of the ...
8
votes
2answers
117 views
Inheriting methods of an immutable type
In my project, I have a type BalanceByBucket that is an immutable type and has a bunch of methods.
I have another class called a ...
1
vote
1answer
57 views
Removing getters for a custom enum [closed]
Recently, I perform re-factor on one of my frequent used custom enum, by removing its getter.
My rational for doing so it.
The enum's custom fields are immutable
Only use getters when it is ...
4
votes
2answers
1k views
Immutable Queue in Java using an Immutable Stack
I am new to this Immutability concept and I have some coding experience in JAVA.
Recently as a part of internship program, they gave me a 5-day task, which was to implement Immutable Queue. After some ...
5
votes
3answers
91 views
Generating a game board with squares in a rectangle
I am trying to generate a game board (similar to a Monopoly board). I am new to Scala and am thinking that there may be a better way to do this. But improvements to the code are also welcome.
...
6
votes
2answers
329 views
Immutable Linked List in VBA
I made an immutable list class using the head-tail idiom. If I did this correctly, it implements persistent data structures. Unfortunately it doesn't scale well ...
6
votes
4answers
1k views
2
votes
3answers
472 views
29
votes
8answers
3k views
Immutable objects in Java
I just finished studying immutable objects and their advantages so I thought I'd create one of my own. Here is my employee class that extends a person class. It is not mutable since I have getters to ...
3
votes
1answer
181 views
Immutable Matrix
I'm writing implementations of some numerical methods to solve linear equations systems, those implementations use the following Matrix class. I'm trying to get this class immutable, due to that the ...
2
votes
2answers
266 views
Replacing an F# loop over a mutable variable by an immutable approach
Consider:
let mutable m' = m
while m' % i = 0L do
m' <- m' / i
I've refactored it into:
...
10
votes
2answers
171 views
Immutable Fraction class
Inspired by this question: Fraction class implemented in Objective-C, I have written what I feel is an improved version of the Fraction class in Objective-C.
As per the tips in this answer, the class ...
3
votes
1answer
167 views
Functional SaveObject in Scala
I came across Java like Scala code that I am trying to refactor to make it functional and immutable. The first obvious flaw is that it's violating thread safety by using mutable public class level ...
6
votes
3answers
22k views
Insert a character into a string
For practicing reasons I would like to write a method which inserts a character into a string.
I would like to know:
What is the best practice concerning placement of a comment within methods? For ...
6
votes
1answer
125 views
Allow changing the properties of a mutable controller in a thread safe way
I have a (control engineering) controller. These controllers usually need several parameters to do their thing, and in my application it is desirable that these parameters can be changed while the ...
5
votes
1answer
1k views
How is my implementation of an immutable stack?
Below is my implementation of an immutable stack class. The reverse function is trying to return a stack with all elements reversed. Is my implementation good? Maybe the reverse function can be ...
4
votes
1answer
580 views
Functional linked list
I'm looking for feedback in general: code correctness, best practices, design patterns; everything you think about this. Is it bad code? Where can it be improved?
I've been implementing functional ...
1
vote
1answer
109 views
Removing redundancy from an immutable “rules class”
I am writing a board game program in Java. Slightly similar to chess or civilization in that each player has a set of units, and each unit has certain actions that it can take.
The base ...
2
votes
1answer
485 views
Creating Proxy classes for immutable objects
As a bit of a learning project, I decided to take the concept of proxying objects a bit further and extend it to creating proxy classes which create proxy'd objects. I originally found the idea of ...
5
votes
1answer
555 views
Immutable C++ stack - thoughts and performance
What are your thoughts on the fallowing immutable stack implementation? It is implemented having as a basis a C# immutable stack (where garbage collector assistance does not impose using a reference ...
1
vote
2answers
179 views
6
votes
1answer
268 views
Circular dependencies between immutable objects; the Freeze Pattern
Generally, I structure small threadsafe immutable objects like this:
...
1
vote
2answers
591 views
Comments on my Java pattern for Mutable turned Immutable objects
Commenting omitted to give you the idea. I've been toying with this recently as a variant of the Builder pattern. I've recently fallen in love with immutable objects for the benefits they give in ...
1
vote
2answers
581 views
4
votes
2answers
798 views
Immutable pure data classes with public setters on properties
I'm putting together some classes as a model for some information (that I'm currently pulling from a website).
The classes are implemented in C# - because in the current version of F# there are no ...