Import std.collections.identity
Identity
struct
Public Struct Identity<T: Class> Implements Hashable
A Class's object as a key by which object it is: equal to another Identity only of the same
object, with RefEquals, and hashed with RefHash, never by the Class's own == or Hash. It
holds its object, which lives as long as the Identity does, as a key does in its Map. An
Identity<Object> is any Class's object, for a Map whose keys are of more than one Class.
Examples
Class Point
Field X: Int
New(x: Int)
X = x
End New
Operator ==(a: Point, b: Point): Bool => a.X == b.X
Method Hash(): UInt64 => X As UInt64
End Class
Local a = Point(1)
Local b = Point(1)
Local names: Map<Identity<Point>, String> = {}
names[Identity(a)] = "first"
names[Identity(b)] = "second"
Expect(names.Count == 2)
a.X = 5
Expect(names.Get(Identity(a)) == "first")std/collections/identity.fb, line 39
-
The object it stands for.
-
The
valueas a key by which object it is. -
RefHash's number for its object.
-
Whether two are of the same object, as RefEquals says.
Report an issue with this page or with FutureBlitz on GitHub.