[go: up one dir, main page]

wing-immutable

Allow `final` to be assigned outside of the constructor.
https://github.com/seiren-games/wing-immutable

To install, run:

haxelib install wing-immutable 1.0.1 

See using Haxelib in Haxelib documentation for more information.

README.md

wing-immutable

Make a variable immutable.
Raise a runtime error on reassignment.

Normally if it is final, it must be assigned in the constructor.
The purpose is to allow the first assignment in other functions.

Usage

class Foo {
	final foo:Immutable<Bool> = new Immutable();

	public function new() {
		setup();
	}
	
	function setup():Void {
		// The first assignment is OK.
		foo.assign(true);
		// By `@:forward` metadata, can be used like the underlying type.
		trace(foo == true);
		
		// After the second time, runtime error.
		foo.assign(false);
	}
}

Tips: When public, Prevent assignment from outside the class

final _foo:Immutable<Bool> = new Immutable();
public var foo(get, never):Bool;
function get_foo():Bool {
	return _foo;
}
Contributors
seiren
Version
1.0.1
Published
4 years ago
License
MIT

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub