handleAs<T> method
T
handleAs<T>({
- T simple()?,
- T bulk()?,
- T integer()?,
- T array()?,
- T error()?,
Calls one of the given handlers based on the
concrete type. Returns true
if a handler for
the concrete type was provided, otherwise false
is returned. If the handler throws an error while
executing, the error is raised to the caller of
this method.
Implementation
T handleAs<T>({
T Function(RespSimpleString)? simple,
T Function(RespBulkString)? bulk,
T Function(RespInteger)? integer,
T Function(RespArray)? array,
T Function(RespError)? error,
}) {
if (isSimpleString && simple != null) {
return simple(toSimpleString());
} else if (isBulkString && bulk != null) {
return bulk(toBulkString());
} else if (isInteger && integer != null) {
return integer(toInteger());
} else if (isArray && array != null) {
return array(toArray());
} else if (isError && error != null) {
return error(toError());
}
throw ArgumentError('No handler provided for type $typeName!');
}