# Implicits
Global state can be hard to reason about, but piping dependencies from function to function is a pain. With implicits, you _explicitly_ which function parameters are _implicit_ dependencies. When you call the function, no need to explicilty provide these parameters; instead, the parameters will be implicitly passed! All that's required is that there exists local variables in scope that match the names of the parameters you're calling.
```python3
@implicits("current_user")
def create_task(title, *, current_user):
print(f"{current_user} created a task titled '{title}'")
current_user = "Jaden"
create_task("Hooray, a task!") # Jaden created a task titled 'Hooray, a task!'
create_task("Buy some trackpants") # Jaden created a task titled 'Buy some trackpants'
```
## Usage
1) Install via `pip install implicits`.
2) Import with `from implicits import implicits`.
3) Decorate using `@implicits("names", "of", "implicit", "parameters")`.
## Example
```python3
import logging
import boto3
from implicits import implicits
class Giraffe:
@implicits("logger")
def __init__(self, name, *, logger):
self.name = name
logger.info(f"Creating a Giraffe named {name}")
@property
@implicits("logger")
def full_name(self, *, logger):
logger.info(f"Getting {self.name}'s full name")
return f"{self.name} the Giraffe"
@property
@implicits("food")
def is_hungry(self, *, food):
return "leaves" in food
@implicits("logger")
def main(*, logger):
jeff = Giraffe("Jeff") # Creating a Giraffe named Jeff
name = jeff.full_name # Getting Jeff's full name
food = ["rocks", "dirt"]
logger.info(jeff.is_hungry) # False
food.append("leaves")
logger.info(jeff.is_hungry) # True
logger = logging.getLogger()
logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler())
main()
```
## References
I didn't invent this idea! Quite a few other languages support implicit parameters. The most mainstream of these languages is Scala. [Check out how implicits work in Scala!](https://docs.scala-lang.org/tour/implicit-parameters.html)
Global state can be hard to reason about, but piping dependencies from function to function is a pain. With implicits, you _explicitly_ which function parameters are _implicit_ dependencies. When you call the function, no need to explicilty provide these parameters; instead, the parameters will be implicitly passed! All that's required is that there exists local variables in scope that match the names of the parameters you're calling.
```python3
@implicits("current_user")
def create_task(title, *, current_user):
print(f"{current_user} created a task titled '{title}'")
current_user = "Jaden"
create_task("Hooray, a task!") # Jaden created a task titled 'Hooray, a task!'
create_task("Buy some trackpants") # Jaden created a task titled 'Buy some trackpants'
```
## Usage
1) Install via `pip install implicits`.
2) Import with `from implicits import implicits`.
3) Decorate using `@implicits("names", "of", "implicit", "parameters")`.
## Example
```python3
import logging
import boto3
from implicits import implicits
class Giraffe:
@implicits("logger")
def __init__(self, name, *, logger):
self.name = name
logger.info(f"Creating a Giraffe named {name}")
@property
@implicits("logger")
def full_name(self, *, logger):
logger.info(f"Getting {self.name}'s full name")
return f"{self.name} the Giraffe"
@property
@implicits("food")
def is_hungry(self, *, food):
return "leaves" in food
@implicits("logger")
def main(*, logger):
jeff = Giraffe("Jeff") # Creating a Giraffe named Jeff
name = jeff.full_name # Getting Jeff's full name
food = ["rocks", "dirt"]
logger.info(jeff.is_hungry) # False
food.append("leaves")
logger.info(jeff.is_hungry) # True
logger = logging.getLogger()
logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler())
main()
```
## References
I didn't invent this idea! Quite a few other languages support implicit parameters. The most mainstream of these languages is Scala. [Check out how implicits work in Scala!](https://docs.scala-lang.org/tour/implicit-parameters.html)
Metadata
Release files for implicits 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| implicits-1.0.2.tar.gz | 2.5 kB | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| implicits-1.0.2-py3-none-any.whl | Python 3 | none | any | Details |
| implicits-1.0.2-py2-none-any.whl | Python 2 | none | any | Details |
Total release size: 9.1 kB
Release files / implicits-1.0.2.tar.gz
| Download URL | implicits-1.0.2.tar.gz |
|---|---|
| Size | 2.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6676e25456c654bf551a95ff208c00279cac559001d24e22c345cc94f838b6ba
|
|
BLAKE2b-256 checksum How to use checksums |
7b760ea282a955c2893a49fc77e44f737f868855386089c3f1e3bed54752d448
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0
|
Release files / implicits-1.0.2-py3-none-any.whl
| Download URL | implicits-1.0.2-py3-none-any.whl |
|---|---|
| Size | 3.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b941cc5c5e8f6f39fe415a3991951fab90267a112299a906cd111aa412c5615d
|
|
BLAKE2b-256 checksum How to use checksums |
8a67aa8d7983b7583fda526171de38c5f3ac6bb5ae5506066c40b06a5fd32d69
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0
|
Release files / implicits-1.0.2-py2-none-any.whl
| Download URL | implicits-1.0.2-py2-none-any.whl |
|---|---|
| Size | 2.8 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
e6aed18a19802b4459bb4098169c66cdedc65d072eef1cff37c753bcf992c6ca
|
|
BLAKE2b-256 checksum How to use checksums |
2778822122504af0e99234ce9cce6d095b0eebc926f36e8e83de96fa782eb09e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0
|