Created
July 21, 2017 05:13
-
-
Save fvosberg/f822f3aa0f2fd9629992aa673331c42f to your computer and use it in GitHub Desktop.
Trying to find a nice and clean solution in python with currying
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python3.6 | |
def init_hr(): | |
number = 0 | |
def inner(): | |
nonlocal number | |
number += 1 | |
print("============================================================================") | |
print("============================== UEBUNG ", number, "===================================") | |
print("============================================================================") | |
print() | |
print() | |
return inner | |
hr = init_hr() | |
hr() | |
hr() | |
hr() | |
# Kind of decorator, although it changes the interface of the function | |
def call_with_sequence_of_numbers(func): | |
number = 0 | |
def wrapper(): | |
nonlocal number | |
number += 1 | |
func(number) | |
return wrapper | |
@call_with_sequence_of_numbers | |
def print_headline(number): | |
print("============================================================================") | |
print("============================== UEBUNG ", number, "===================================") | |
print("============================================================================") | |
print() | |
print() | |
print_headline() | |
print_headline() | |
print_headline() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment