EntilZha / PyFunctional

Python library for creating data pipelines with chain functional programming
http://pyfunctional.pedro.ai
MIT License
2.41k stars 132 forks source link

Add "peek" feature, similar to that of Java Streams API #166

Closed kchro3 closed 3 years ago

kchro3 commented 3 years ago

Here is a proposal for an idiomatic way to do a "peek" operation (https://www.baeldung.com/java-streams-peek-api).

TL;DR: In Java, you can call .peek( someFn ) as an intermediate step in the pipeline, but it wouldn't modify the value like .map would.

# for example
(
  seq(1, 2, 3)
  .map(lambda x: x ** 2)
  .peek(print)
  .to_set()
)

I think it could be helpful for logging / maintaining stats / debugging purposes.

codecov[bot] commented 3 years ago

Codecov Report

Merging #166 (13df3cb) into master (d757a90) will increase coverage by 0.01%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #166      +/-   ##
==========================================
+ Coverage   97.98%   98.00%   +0.01%     
==========================================
  Files          12       12              
  Lines        2237     2253      +16     
==========================================
+ Hits         2192     2208      +16     
  Misses         45       45              
Impacted Files Coverage Δ
functional/pipeline.py 98.09% <100.00%> (+<0.01%) :arrow_up:
functional/test/test_functional.py 98.94% <100.00%> (+<0.01%) :arrow_up:
functional/transformations.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update d757a90...13df3cb. Read the comment docs.

EntilZha commented 3 years ago

Thanks for the PR!