Skip to content

Instantly share code, notes, and snippets.

@hanepjiv
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hanepjiv/0aeb12d4d20da60d46ae to your computer and use it in GitHub Desktop.
Save hanepjiv/0aeb12d4d20da60d46ae to your computer and use it in GitHub Desktop.
# 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