call method
Invokes the function item with the given arguments.
Implementation
@override
XPathSequence call(XPathContext context, List<XPathSequence> arguments) {
if (arguments.length != 1) {
throw XPathEvaluationException(
XPathErrorCode.FOAP0001,
'Arrays expect exactly 1 argument, but got ${arguments.length}',
);
}
final arg = arguments.single.atomize().firstOrNull;
if (arg is! XPathInteger) {
throw XPathEvaluationException(
XPathErrorCode.XPTY0004,
'Array index must be an integer, got ${arg?.type}',
);
}
final idx = arg.value.toInt();
if (idx < 1 || idx > members.length) {
throw XPathEvaluationException(
XPathErrorCode.FOAY0001,
'Array index out of bounds: $idx (length: ${members.length})',
);
}
return members[idx - 1];
}