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

Add 'traces' function #301

Closed
sushi-shi opened this issue May 28, 2020 · 5 comments · Fixed by #303
Closed

Add 'traces' function #301

sushi-shi opened this issue May 28, 2020 · 5 comments · Fixed by #303
Labels
new Bring something new into library (add function or type or interface)

Comments

@sushi-shi
Copy link
Contributor

sushi-shi commented May 28, 2020

traceShowId is really useful because you can plug it in anywhere you want without restructuring your code, however, sometimes it outputs too much, or things you use it on do not have Show instance.
So I propose to add a simple traces function:

traces :: Show b => (a -> b) -> a -> a
traces f v = traceShow (f v) v

> fst $ traces fst (5, id)
> 5
> 5

Though it may clash with traces function defined in comonad package. However Control.Comonad.Traced also has trace, so one would need to be careful with this module anyway.

@chshersh chshersh added the new Bring something new into library (add function or type or interface) label May 28, 2020
@chshersh chshersh added this to the v0.8.0.0: Standard milestone May 28, 2020
@chshersh
Copy link
Contributor

@sheepfleece Thanks for the proposal! This function sounds useful; I don't mind adding it to relude. I'm not worried that much about the collision with the traces function from the comonad package, I'm more concerned about the collision with variables that have name traces (it's a legit variable name). So let's think more about the name. Maybe a different name that has fewer chances to conflict can be introduced (e.g. traceFun or traceWithShow or traceOn).

@sushi-shi
Copy link
Contributor Author

@chshersh Thank you! I think traceFun sounds good enough. It may be less elegant then traceOn (and, of course, traces). However, when grepping a subset of Hackage I have locally downloaded it didn't find a single hit, compared to the other two. And traceFun is also easy to remember, in contrast with traceWithShow.

@chshersh
Copy link
Contributor

chshersh commented Jun 1, 2020

@sheepfleece We've been thinking and discussing with @vrom911 possible names and consistent naming schemes for trace* functions and decided to stick with traceShowWith. It makes sense, that we have traceShow and traceShowWith adds an extra ability to the existing function (it also consistent with sortWith). PR is welcome 🙂

@chshersh chshersh mentioned this issue Jun 2, 2020
10 tasks
sushi-shi pushed a commit to sushi-shi/relude that referenced this issue Jun 4, 2020
@sushi-shi sushi-shi mentioned this issue Jun 4, 2020
10 tasks
sushi-shi pushed a commit to sushi-shi/relude that referenced this issue Jun 5, 2020
chshersh pushed a commit that referenced this issue Jun 5, 2020
* [#301] Add traceShowWith

* [#301] Add more examples
@elldritch
Copy link
Contributor

Hey @chshersh, any plans on doing a new release any time soon? I've been running into situations in Advent where having this combinator would be really useful.

@chshersh
Copy link
Contributor

@liftM We work on relude in our free time, and our work depends on availability, so we don't have any deadlines or release schedules. But we do have milestones to plan what we want to include in the next release.

Nevertheless, this shouldn't be a blocker for you if you want to use the latest version of relude in your own projects, as you can depend on packages directly from GitHub with either Cabal or Stack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new Bring something new into library (add function or type or interface)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants