immutable 0.10.5

Enforce immutability.

Released 2016-06-17.

To install, run:

haxelib install immutable 0.10.5

See using Haxelib in Haxelib documentation for more information.

Current version0.10.5
StatisticsInstalled 172 times
Tags cross, fp, immutable


Make your classes and local vars immutable with

haxelib install immutable

-lib immutable

class YourClass implements Immutable
	public var test : String;

	// Fields can be mutable, but will emit a compiler warning:
	@mutable public var specialCase : String;

	public function new() {
		test = "It's ok to assign in the constructor";

	public function test() {
		var a = 123;
		a = 234; // *** Compilation error

		@mutable var b = 123;
		b = 234; // Ok

		this.test = "mutated!"; // *** Compilation error, incl. external access
		this.specialCase = "special"; // Ok

The library is using macros for enforcing this at compile-time only, so it won't slow down your code. It may affect compilation time a bit, so in certain cases you may choose to disable all checking with -D disable-immutable.


When implementing Immutable, vars will behave like const and let, used in modern javascript:

const a = 123;var a = 123;
let b = 234;@mutable var b = 234;

For local vars only

If you want your class vars and properties to behave as usual, you can implement ImmutableLocalVars instead, and it will only affect vars in methods.


Please open an issue if you happened to trick the library, or if you think something is conceptually or semantically wrong. Using Reflect isn't tricking though, it's intentional!

Build Status