Last active
August 29, 2015 14:10
-
-
Save hanepjiv/0aeb12d4d20da60d46ae 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
# coding: utf-8 | |
# http://hanepjiv.blogspot.jp/2014/11/python-indentchoice.html | |
from functools import wraps | |
# ================================================ | |
def choice(a_Func): | |
# -------------------------------------------------------------------------- | |
def loop(*args): | |
if len(args) is 0: | |
return [] | |
if len(args[1:]) is 0: | |
return [[i] for i in args[0]] | |
return [[i] + j for i in args[0] for j in loop(*args[1:])] | |
# -------------------------------------------------------------------------- | |
@wraps(a_Func) | |
def wrapper(*args): | |
return [i for i in map((lambda args: a_Func(*args)), loop(*args))] | |
return wrapper | |
@choice | |
def hoge(*args): | |
return tuple(args) | |
print(hoge((0,), (1,2), (3,4,5), (6,7,8,9))) | |
@choice | |
def fuga(*args): | |
return sum(args) | |
print(fuga((0,), (1,2), (3,4,5), (6,7,8,9))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment