-
-
Save fajran/1480532 to your computer and use it in GitHub Desktop.
This file contains 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
def angka(): | |
return 10 | |
print angka() |
This file contains 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
def kali_sepuluh(func): | |
def inner_func(): | |
hasil = func() | |
return 10 * hasil | |
return inner_func | |
@kali_sepuluh | |
def angka(): | |
return 10 | |
def angka_juga(): | |
return 20 | |
angka_juga_decorated = kali_sepuluh(angka_juga) | |
print angka() | |
print angka_juga() | |
print angka_juga_decorated() |
This file contains 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
def api(func): | |
def inner(request): | |
hasil = func(request) | |
return HttpResponse(json.dumps(hasil)) | |
return inner | |
@api | |
def daftar_angka(request): | |
hasil = ['satu', 'dua', 'tiga'] | |
return hasil |
This file contains 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
def int_only(func): | |
def cek_input(*args): | |
args_filtered = [] | |
for arg in args: | |
if type(arg) == int: | |
args_filtered.append(arg) | |
return func(*args_filtered) | |
return cek_input | |
@int_only | |
def cetak(*args): | |
print 'Cetak:' | |
for arg in args: | |
print '-', arg | |
cetak(1, 2, 'tiga', 'empat', 5, 6, object(), None, 'sembilan', 10) |
This file contains 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
def str_only(func): | |
def cek_output(*args): | |
hasil = func(*args) | |
filtered = [] | |
for item in hasil: | |
if type(item) == str: | |
filtered.append(item) | |
return filtered | |
return cek_output | |
@str_only | |
def apalah(): | |
return ['satu', 2, 3, 'empat', None, 6, 'tujuh'] | |
print apalah() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment