Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tap): added 'tap' function #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

feat(tap): added 'tap' function #17

wants to merge 2 commits into from

Conversation

dggluz
Copy link
Collaborator

@dggluz dggluz commented Oct 7, 2018

Description

Adds the tap function, that calls a function and returns its parameter.

Related issues

@dggluz dggluz requested a review from hrajchert October 7, 2018 06:17
README.md Outdated
@@ -104,6 +104,31 @@ const rejectedTask = Task.resolve(new Error());
const rejectedPromise = toPromise(rejectedTask);
```

### `tap`

The `tap` _function_ can be found in other libreries. It just takes a `callback` _function_ and return a function that calls the `callback` and _returns_ the _argument_. It's useful when you need to perform some side effect. Suppose you need to log the _resolved value_ at certain point of a `Task` _method chaining_. Without the `tap` _function_ you would probably do something like:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libraries...
Too many functions... try to modify with: It takes a callback and returns a function that invokes the callback with the parameter and pass it trough

README.md Outdated
Task
.resolve(0)
// <Some code here...>
.map(tap(console.log))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this works? when using console.log as a point free function weird things can happen

@hrajchert
Copy link
Contributor

Gonza, cuando quieras reviví este PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants