varargs 0.1.0 copy "varargs: ^0.1.0" to clipboard
varargs: ^0.1.0 copied to clipboard

outdated

An `extension` on specific `Functions`s to help developers easily implement the `Function` wit variable length arguments.

varargs package #

This package helps developers implement variable length argument functions easily. The functionality is provided as a extension on specific Function. See the example for the details

Example #

import 'package:varargs/varargs.dart';

/// The first arguments is a `List<dynamic>` of the positioned arguments,
/// and the second arguments is a `Map<Symbol, dynamic>` of the named arguments.
/// If you want to access a named argument, you should use the `Symbol`
/// instead of the variable name which is usually a `String`.
/// See the below examples in the `example/` directory.
int echo(List positioned, Map named) {
  if (named.containsKey('key')) {
    // This condition does not pass the test.
    // You can not use a `String` to a key.
    print(named['key']);
  }
  // The first method to access the named arguments.
  if (named.containsKey(#key2)) {
    print(named[#key2]);
  }
  // The second method to access the named arguments.
  if (named.containsKey(Symbol('key3'))) {
    print(named[#key3]);
  }
  return positioned.length + named.length;
}

/// You can also create async functions.
Future<int> asyncEcho(List positioned, Map named) async {
  print('This is an async varargs function');
  return positioned.length + named.length;
}

void main(List<String> arguments) async {
  /// You should call your functions with `varArgs` to transfer the varargs to your functions.
  final result = echo.varArgs(
    3,
    2,
    1,
    2,
    3,
    key: 'key with stringified symbol',
    key2: 'key2 with #',
    key3: 'key3 with `Symbol`',
  );
  print(result);
  print(await asyncEcho.varArgs(3, 2, 1, 2, 3, 2, 2, 3, hi: 'hihi'));
}

3
likes
20
pub points
10%
popularity

Publisher

verified publishergihwan.com

An `extension` on specific `Functions`s to help developers easily implement the `Function` wit variable length arguments.

License

unknown (LICENSE)

More

Packages that depend on varargs