2015-11-23 16:39:19 +03:00
|
|
|
"""`Callable` providers with positional arguments example."""
|
2015-10-22 16:51:16 +03:00
|
|
|
|
2016-06-06 11:54:05 +03:00
|
|
|
import dependency_injector.providers as providers
|
2015-10-22 16:51:16 +03:00
|
|
|
|
|
|
|
|
|
|
|
# Creating even and odd filter providers:
|
2015-11-23 16:39:19 +03:00
|
|
|
even_filter = providers.Callable(filter, lambda x: x % 2 == 0)
|
|
|
|
odd_filter = providers.Callable(filter, lambda x: x % 2 != 0)
|
2015-10-22 16:51:16 +03:00
|
|
|
|
2016-11-02 19:22:17 +03:00
|
|
|
# Creating even and odd ranges using range() and filter providers:
|
|
|
|
even_range = even_filter(range(1, 10))
|
|
|
|
odd_range = odd_filter(range(1, 10))
|
2015-10-22 16:51:16 +03:00
|
|
|
|
|
|
|
# Making some asserts:
|
|
|
|
assert even_range == [2, 4, 6, 8]
|
|
|
|
assert odd_range == [1, 3, 5, 7, 9]
|