Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/seiren-games/wing-immutable
Immutable variable
https://github.com/seiren-games/wing-immutable
haxe immutable
Last synced: 3 months ago
JSON representation
Immutable variable
- Host: GitHub
- URL: https://github.com/seiren-games/wing-immutable
- Owner: seiren-games
- License: mit
- Created: 2021-10-07T13:49:50.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-09-24T07:50:38.000Z (over 2 years ago)
- Last Synced: 2024-07-29T18:44:20.736Z (5 months ago)
- Topics: haxe, immutable
- Language: Haxe
- Homepage:
- Size: 19.5 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# wing-immutable
Make a variable immutable.
Raise a runtime error on reassignment.Normally if it is final field, it must be assigned in the constructor.
The purpose is to allow the first assignment in other functions.# Usage
```haxe
import wing.Immutable;class Foo {
final foo:Immutable = 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
```haxe
final _foo:Immutable = new Immutable();
public var foo(get, never):Null;
inline function get_foo():Null {
return _foo;
}
```
or
```haxe
final foo:Immutable = new Immutable();
public inline function getFoo():Null {
return foo;
}
```