Friendlier accessors
This commit is contained in:
parent
921fe7dfd2
commit
320cb894f1
|
@ -373,6 +373,15 @@ Record.makeBasicConstructor = function (label, fieldNames) {
|
|||
ctor.isClassOf = (v) => ((v instanceof Record) &&
|
||||
is(label, v.label) &&
|
||||
v.fields.size === arity);
|
||||
fieldNames.forEach((name, i) => {
|
||||
ctor['_'+name] = function (r) {
|
||||
if (!ctor.isClassOf(r)) {
|
||||
throw new Error("Record: attempt to retrieve field "+label+"."+name+
|
||||
" from non-"+label+": "+(r && r.toString()));
|
||||
}
|
||||
return r.get(i);
|
||||
};
|
||||
});
|
||||
return ctor;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue