mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-27 12:04:00 +03:00
17 lines
520 B
Python
17 lines
520 B
Python
"""`Callable` providers with positional arguments example."""
|
|
|
|
import dependency_injector.providers as providers
|
|
|
|
|
|
# Creating even and odd filter providers:
|
|
even_filter = providers.Callable(filter, lambda x: x % 2 == 0)
|
|
odd_filter = providers.Callable(filter, lambda x: x % 2 != 0)
|
|
|
|
# Creating even and odd ranges using range() and filter providers:
|
|
even_range = even_filter(range(1, 10))
|
|
odd_range = odd_filter(range(1, 10))
|
|
|
|
# Making some asserts:
|
|
assert even_range == [2, 4, 6, 8]
|
|
assert odd_range == [1, 3, 5, 7, 9]
|