dart_collection_sampler 2.0.1
dart_collection_sampler: ^2.0.1 copied to clipboard

Dart native js
Flutter Android iOS web

a small library implementing methods to sample items from collections

example/main.dart

import 'dart:io';

import 'package:args/args.dart';
import 'package:dart_collection_sampler/dart_collection_sampler.dart';

void main(List<String> arguments) {
  var argParser = ArgParser()
    ..addOption("num",
        abbr: "n",
        help: "items to pick from rest of command line",
        defaultsTo: "1")
    ..addFlag("unique",
        abbr: "u",
        help: "select unique results",
        defaultsTo: false,
        negatable: false);

  var results = argParser.parse(arguments);

  exit(deal(int.parse(results["num"]), results.rest, results['unique']));
}

int deal(int n, List<String> items, bool unique) {
  if (items.isEmpty) {
    print("you must supply one or more items as input");
    return 1;
  }
  print("Picking $n from $items (unique: $unique)\n");

  if (n == 1) {
    print("Selected item: ${CollectionSampler().pick(items)}");
  } else {
    print(
        "Selected items: ${CollectionSampler().pickN(items, n, unique: unique)}");
  }
  return 0;
}
0
likes
100
pub points
15%
popularity

a small library implementing methods to sample items from collections

Repository (GitHub)
View/report issues

Documentation

API reference

Uploaders

stevec1973@gmail.com
adventuresmith.rpg@gmail.com

License

MIT (LICENSE)

Dependencies

dart_dice_parser

More

Packages that depend on dart_collection_sampler