cool

Make Python code cooler. Less is more.

https://github.com/abersheeran/cool

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (9.5%) to scientific vocabulary

Keywords

pipeline python redirect
Last synced: 6 months ago · JSON representation

Repository

Make Python code cooler. Less is more.

Basic Info
  • Host: GitHub
  • Owner: abersheeran
  • License: apache-2.0
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 51.8 KB
Statistics
  • Stars: 140
  • Watchers: 3
  • Forks: 12
  • Open Issues: 2
  • Releases: 0
Topics
pipeline python redirect
Created about 5 years ago · Last pushed almost 3 years ago
Metadata Files
Readme Funding License

README.md

Cool.py

Make Python code cooler. 100% coverage. Use and enjoy this code!

Install

pip install cool

Or fetch from github

pip install git+https://github.com/abersheeran/cool@setup.py

Usage

Pipe

Note: as fast as you didn't use F!

Use pipeline to pass data as a positional parameter to the next function.

```python from cool import F

assert range(10) | F(filter, lambda x: x % 2) | F(sum) == 25 ```

Or you need to pass multiple parameters through the pipeline. Note that FF can only accept one parameter, and it must be an iterable object.

```python from cool import FF

assert (1, 2) | FF(lambda x, y: x + y) == 3 ```

You can use ... as a placeholder. This is useful when you need to pass non-continuous parameters to create a partial function.

```python from functools import reduce from cool import F

assert range(10) | F(reduce, lambda x, y: x + y) == 45 assert range(10) | F(reduce, lambda x, y: x + y, ..., 10) == 55

square = F(pow, ..., 2) assert range(10) | F(map, square) | F(sum) == 285 ```

The range(10) | F(reduce, lambda x, y: x + y, ..., 10) is equivalent to reduce(lambda x, y: x + y, range(10), 10).

Redirect

Just like the redirection symbol in Shell, you can redirect the output to a specified file or TextIO object through > or >>.

```python from pathlib import PurePath from cool import R

Redirect output to specified filepath

R(lambda : print("hello")) > PurePath("your-filepath")

Append mode

R(lambda : print("hello")) >> PurePath("your-filepath") ```

Redirect to opened file or other streams.

```python from io import StringIO from cool import R

with open("filepath", "a+", encoding="utf8") as file: R(lambda : print("hello")) >> file

out = StringIO("") R(lambda : print("hello")) > out out.seek(0, 0) assert out.read() == "hello\n" ```

Maybe you also want to block the output, just like > /dev/null.

```python from cool import R

R(lambda : print("hello")) > None

Or

R(lambda : print("hello")) >> None ```

Note that after the calculation is over, R will faithfully return the return value of your function. Try the following example.

```python from pathlib import PurePath from cool import F, R

def func(num): return range(num) | F(map, lambda x: print(x) or x) | F(sum)

result = R(lambda : func(10)) > PurePath("filepath") assert result == 45 ```

Set Global

Maybe you don't want to use from cool import F in every file of the entire project, you can use the following code to set it as a global function, just like min/max/sum.

```python import cool

cool.set_global(cool.F, cool.FF) ```

Maybe you also want to expose functools.reduce to the world, just like map/filter.

```python import functools import cool

cool.set_global(cool.F, cool.FF, functools.reduce) ```

Owner

  • Name: Aber
  • Login: abersheeran
  • Kind: user
  • Location: 中国

Senior engineer. Full stack. A hacker without 0day.

GitHub Events

Total
  • Watch event: 2
Last Year
  • Watch event: 2

Committers

Last synced: 12 months ago

All Time
  • Total Commits: 36
  • Total Committers: 1
  • Avg Commits per committer: 36.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
abersheeran me@a****m 36
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 8 months ago

All Time
  • Total issues: 0
  • Total pull requests: 5
  • Average time to close issues: N/A
  • Average time to close pull requests: 6 minutes
  • Total issue authors: 0
  • Total pull request authors: 2
  • Average comments per issue: 0
  • Average comments per pull request: 0.8
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
  • abersheeran (4)
  • imlyzh (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 122 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 2
  • Total versions: 7
  • Total maintainers: 1
pypi.org: cool
  • Versions: 7
  • Dependent Packages: 0
  • Dependent Repositories: 2
  • Downloads: 122 Last month
Rankings
Stargazers count: 6.9%
Dependent packages count: 10.0%
Dependent repos count: 11.6%
Forks count: 11.9%
Average: 12.9%
Downloads: 24.1%
Maintainers (1)
Last synced: 6 months ago

Dependencies

poetry.lock pypi
  • appdirs 1.4.4 develop
  • black 20.8b1 develop
  • click 7.1.2 develop
  • dataclasses 0.6 develop
  • enum34 1.1.10 develop
  • flake8 3.8.4 develop
  • functools32 3.2.3-2 develop
  • mccabe 0.6.1 develop
  • mypy-extensions 0.4.3 develop
  • pathspec 0.8.0 develop
  • pycodestyle 2.6.0 develop
  • pyflakes 2.2.0 develop
  • regex 2020.9.27 develop
  • toml 0.10.1 develop
  • typed-ast 1.4.1 develop
  • typing 3.7.4.3 develop
  • typing-extensions 3.7.4.3 develop
  • atomicwrites 1.4.0
  • attrs 20.2.0
  • backports.functools-lru-cache 1.6.1
  • colorama 0.4.3
  • configparser 4.0.2
  • contextlib2 0.6.0.post1
  • coverage 5.4
  • importlib-metadata 2.0.0
  • more-itertools 8.5.0
  • packaging 20.4
  • pathlib2 2.3.5
  • pluggy 0.13.1
  • py 1.9.0
  • pyparsing 2.4.7
  • pytest 5.4.3
  • pytest-cov 2.11.1
  • six 1.15.0
  • wcwidth 0.2.5
  • zipp 3.3.0
pyproject.toml pypi
  • black * develop
  • flake8 * develop
  • pytest ^5.4.3 develop
  • pytest-cov ^2.11.1 develop
  • python ~2.7 || ^3.5
.github/workflows/setup.yml actions
  • actions/checkout v1 composite
  • actions/setup-python v1 composite
.github/workflows/test.yml actions
  • actions/checkout v1 composite
  • actions/setup-python v1 composite