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
Repository
Make Python code cooler. Less is more.
Basic Info
Statistics
- Stars: 140
- Watchers: 3
- Forks: 12
- Open Issues: 2
- Releases: 0
Topics
Metadata Files
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: 中国
- Website: https://donate.aber.sh
- Repositories: 67
- Profile: https://github.com/abersheeran
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
Top Committers
| Name | 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
- Homepage: https://github.com/abersheeran/cool
- Documentation: https://cool.readthedocs.io/
- License: Apache-2.0
-
Latest release: 0.4.0
published almost 5 years ago
Rankings
Maintainers (1)
Dependencies
- 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
- black * develop
- flake8 * develop
- pytest ^5.4.3 develop
- pytest-cov ^2.11.1 develop
- python ~2.7 || ^3.5
- actions/checkout v1 composite
- actions/setup-python v1 composite
- actions/checkout v1 composite
- actions/setup-python v1 composite