https://github.com/kyleect/tap
A typescript implementation of Ruby's tap method
https://github.com/kyleect/tap
Last synced: about 1 year ago
JSON representation
A typescript implementation of Ruby's tap method
- Host: GitHub
- URL: https://github.com/kyleect/tap
- Owner: kyleect
- License: mit
- Created: 2016-05-24T03:36:33.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-05-27T02:09:02.000Z (almost 10 years ago)
- Last Synced: 2025-01-14T06:16:01.637Z (about 1 year ago)
- Language: TypeScript
- Size: 26.4 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Tap
[](https://travis-ci.org/maexsoftware/tap)
A typescript implementation of Ruby's tap.
## Usage
If you want to get started right away then you can extend `TappableClass`. This
will give you a basic implementation of the tap method.
```ts
class BasicExampleClass extends TappableClass {
public value:number = 0;
public get ():number {
return this.value;
}
public set (value:number):this {
this.value = value;
return this;
}
}
const example = new BasicExampleClass();
example
.set(10)
.set(20)
.tap(value => console.log(value)) // 20
.set(30)
.get(); // 30
```
If you want more control over the tap method implementation for your class then
you can simply implement `ITappableClass` with your own implementation.
```ts
class ExampleClass implements ITappableClass {
tap (fn: (value: this) => void): this {
const clone:this = Object.assign({ __proto__: Object.getPrototypeOf(this) }, this);
const froze:this = Object.freeze(clone);
fn.call(null, froze);
return this;
}
}
```