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
| /*-- scss:defaults --*/ | |
| @import url(https://fonts.googleapis.com/css?family=Josefin+Sans&display=swap); | |
| @import url(https://fonts.googleapis.com/css?family=Fira+Mono&display=swap); | |
| @import url(https://fonts.googleapis.com/css?family=Zen+Kaku+Gothic+Antique:500&display=swap); | |
| @import url(https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@500&display=swap); | |
| // fonts | |
| $font-family-sans-serif: "Noto Sans JP", "Zen Kaku Gothic Antique", sans-serif !default; | |
| $font-family-monospace: "Fira Mono", monospace !default; |
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
| def curry(func): | |
| def curried(*args): | |
| if len(args) == func.__code__.co_argcount: | |
| return func(*args) | |
| return lambda x: curried(*args, x) | |
| return curried | |
| @curry |
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
| import functools | |
| def flip(func): | |
| @functools.wraps(func) | |
| def wrapper(*args, **kwargs): | |
| new_args = args[::-1] | |
| return func(*new_args, **kwargs) | |
| return wrapper | |
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
| from functools import wraps | |
| def decorator1(func): | |
| @wraps(func) | |
| def wrapper(*args, **kwargs): | |
| print("Decorator 1") | |
| return func(*args, **kwargs) | |
| return wrapper | |
| def decorator2(func): |
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
| def no_reassign(*arg_names): | |
| def decorator(func): | |
| def wrapper(*args, **kwargs): | |
| original_args = args # 引数をコピーしておく | |
| result = func(*args, **kwargs) # 関数を実行する | |
| # 指定した引数が変更された場合に例外を発生させる | |
| for i, arg_name in enumerate(arg_names): | |
| arg_value = kwargs.get(arg_name, args[i]) | |
| if arg_value != original_args[i]: | |
| raise TypeError("cannot reassign argument '{}'".format(arg_name)) |
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
| class ConstantSpace: | |
| def __init__(self, **kwargs): | |
| # ユーザーが指定した値を格納する辞書 | |
| self._data = kwargs | |
| def __setattr__(self, name, value): | |
| # 既存の属性を変更しようとした場合はエラーを発生させる | |
| if name in self._data: | |
| raise AttributeError(f"'ConstantSpace' object attribute '{name}' is read-only") | |
| # 新しい属性を追加しようとした場合はエラーを発生させる |
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
| class Infix: | |
| def __init__(self, func): | |
| self.func = func | |
| def __ror__(self, other): | |
| return Infix(lambda x: self.func(other, x)) | |
| def __or__(self, other): | |
| return self.func(other) |
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
| import inspect | |
| def log_arguments(func): | |
| def wrapper(*args, **kwargs): | |
| signature = inspect.signature(func) | |
| bound_arguments = signature.bind(*args, **kwargs) | |
| bound_arguments.apply_defaults() | |
| args_list = [] | |
| for name, value in bound_arguments.arguments.items(): | |
| arg_type = ( |
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
| import functools | |
| def flip(func): | |
| @functools.wraps(func) | |
| def wrapper(*args, **kwargs): | |
| new_args = args[::-1] | |
| return func(*new_args, **kwargs) | |
| return wrapper | |
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
| def compose(*functions): | |
| def inner(arg): | |
| for function in reversed(functions): | |
| arg = function(arg) | |
| return arg | |
| return inner | |
| def add2(x): | |
| return x + 2 |
NewerOlder