GithubHelp home page GithubHelp logo

kseo / tap Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 7 KB

Ruby's Object#tap for Dart

Home Page: https://pub.dartlang.org/packages/tap

License: BSD 3-Clause "New" or "Revised" License

Dart 79.68% Shell 20.32%

tap's Introduction

tap

This package provides Ruby's Object#tap method for Dart.

Build Status Coverage Status

Usage

The primary purpose of this method is to “tap into” a method chain, in order to perform operations on intermediate results within the chain.

import 'package:quiver_collection/collection.dart';
import 'package:tap/tap.dart';

List<int> gen(int n) => new List<int>.generate(n, (i) => i);

class MyList<E> extends DelegatingList<E> with TapMixin<MyList<E>> {
  final List<E> _base = new List<E>();

  @override
  List<E> get delegate => _base;

  @override
  String toString() => _base.toString();
}

main() {
  final xs = new MyList<int>()..addAll(gen(10));
  xs
    ..tap((xs) => print('original: $xs'))
    ..removeWhere((x) => x % 2 == 0)
    ..tap((xs) => print('removed: $xs'))
    ..shuffle()
    ..tap((xs) => print('shuffled: $xs'))
    ..sort()
    ..tap((xs) => print('sorted: $xs'));
  // original: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  // removed: [1, 3, 5, 7, 9]
  // shuffled: [3, 1, 7, 9, 5] (can differ)
  // sorted: [1, 3, 5, 7, 9]
}

Features and bugs

Please file feature requests and bugs at the issue tracker.

tap's People

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.