scala / scala-library-next

backwards-binary-compatible Scala standard library additions
Apache License 2.0
69 stars 17 forks source link

WIP: Future and try tap each #45

Open sinanspd opened 3 years ago

sinanspd commented 3 years ago

Addresses #44

As originally discussed in scala/scala#8857 :

1) Defines tapEach for Try 2) Defines tapEach for Futures, using transform, leveraging the existing implementation for Try

Following the pattern that was laid in the previous PRs. Marking WIP because of the following mainly:

1) Because Try is an abstract class, the pattern looks slightly different. I haven't been able to find an elegant method to define an extension method for each instance AND the abstract class, and still have things dispatch properly. I went with pattern matching to dispatch things here but it means that this extension method will need to be broken into 3 pieces, should this be ever merged into stdlib

2) I open to suggestions for testing Futures (or testing this in general since we are testing side effects). Junit doesn't seem to be very fond of awaiting. I am looking at the Future Test in the Scala Repo and that seems to be very basic and isn't asserting any values.

Appreciate any feedback.