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 conversion of sequences to JSON #139

Closed fkromer closed 4 years ago

fkromer commented 5 years ago

I am writing a command line app and need human readable output of sequences/streams. In my particular use case (nested sequences) pretty-printed JSON would be most suitable. Right now to_json writes JSON to a file. Could we add plain conversion (similar to to_dict) to JSON?

EntilZha commented 4 years ago

The easy fix would be doing something like

seq.range(20).foreach(lambda x: print(json.dumps(x)))

Alternatively, you could use the extend feature (should really write docs for this) https://github.com/EntilZha/PyFunctional/pull/144

import functional
import json

@functional.pipeline.extend(final=True) 
def to_json(elements): 
    return json.dumps(elements)                                                                                                                                                 

functional.seq.range(10).to_json()                                                                                                                    
# '[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]'
stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

fkromer commented 4 years ago

@EntilZha Thanks for letting me know.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.