question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implement tee/tap for functors?

See original GitHub issue

The generic iter takes a functor and an action to perform, and returns unit.

I’d like a similar function that passes through the functor, i.e. performs a unit-returning action and then returns the original input (for further chaining). As I understand it, this is typically called tee or tap. Could this be added?

Le me know if this is unclear and I should provide more details.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
gustycommented, Jan 12, 2020

@cmeeren Sorry about my poor explanation, here’s a (hopefully) better attempt.

Result<'T,'U> (read 'T and 'U as variable types) is a bifunctor, as I can map a ('T -> 'A) and a ('U -> 'B) and get a "bimapped"version of it.

Now, Result<'T,unit> (unit or another fixed type) is not, because I can’t map any function to the right side, I could only map a unit->unit function, otherwise I would end up with a different type.

1reaction
gustycommented, Dec 19, 2019

@wallymathieu I think tap is also used in Scala.

@cmeeren well, the composition is backwards map << tee but you’re right in that it won’t be efficient.

An easy alternative is let inline ftee f x = iter f x; x

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure functions debug fails to start on a non-trivial project
When I create new Azure Functions project (.NET 5 isolated) right from the start debugging it works fine. But after some code changes ......
Read more >
Why is the constant always dropped from big O analysis?
Multiplying a function by a constant only influences its growth rate by a constant amount, so linear functions still grow linearly, logarithmic ...
Read more >
Keep your app visible on Wear
For apps that require more frequent updates, use an AlarmManager object to wake the processor and update the screen more frequently. To ...
Read more >
Individual or group. (27 Responses)
The use of the term "protection functions" is not a defined NERC term and ... An example would be for a tee-tap off...
Read more >
Japan high-tech "washlets" aim at U.S. bottoms
The name belongs to its product line Washlet, but is used in Japan as a generic term for all high-tech toilets with bidet...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found