when<T> method

T when<T>({
  1. required T string(
    1. StringValueNode
    ),
  2. required T int_(
    1. IntValueNode
    ),
  3. required T float(
    1. FloatValueNode
    ),
  4. required T boolean(
    1. BooleanValueNode
    ),
  5. required T object(
    1. ObjectValueNode
    ),
  6. required T list(
    1. ListValueNode
    ),
  7. required T enum_(
    1. EnumValueNode
    ),
  8. required T null_(
    1. NullValueNode
    ),
  9. required T variable(
    1. VariableNode
    ),
})

Executes the given callback when this is of the type parameter

Implementation

T when<T>({
  required T Function(ast.StringValueNode) string,
  required T Function(ast.IntValueNode) int_,
  required T Function(ast.FloatValueNode) float,
  required T Function(ast.BooleanValueNode) boolean,
  required T Function(ast.ObjectValueNode) object,
  required T Function(ast.ListValueNode) list,
  required T Function(ast.EnumValueNode) enum_,
  required T Function(ast.NullValueNode) null_,
  required T Function(ast.VariableNode) variable,
}) {
  final v = this;
  if (v is ast.StringValueNode) return string(v);
  if (v is ast.IntValueNode) return int_(v);
  if (v is ast.FloatValueNode) return float(v);
  if (v is ast.BooleanValueNode) return boolean(v);
  if (v is ast.ObjectValueNode) return object(v);
  if (v is ast.ListValueNode) return list(v);
  if (v is ast.EnumValueNode) return enum_(v);
  if (v is ast.NullValueNode) return null_(v);
  if (v is ast.VariableNode) return variable(v);
  throw Error();
}