Created
March 4, 2021 12:58
-
-
Save masakih/21de45479b4389e29b727487d249ac8c to your computer and use it in GitHub Desktop.
これでSwiftのソースを作ってみたけどswiftcが帰ってこないw #CodePiece
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 commaSep(array): | |
| return ', '.join(array) | |
| def closure(n, param): | |
| if n == 1: | |
| return '{ p' + str(len(param) - n) + ' in f(' + commaSep(param) + ') } ' | |
| return '{ p' + str(len(param) - n) + ' in ' + closure(n - 1, param) + '} ' | |
| def body(p): | |
| return closure(len(p), ['p' + str(i) for i in range(0, len(p), 1)]) | |
| p = [chr(i) for i in range(ord('A'), ord('Z') + 1)] | |
| typeslist = [p[:i] for i in range(2, len(p) + 1, 1)] | |
| rtype = 'ResultValue' | |
| }% | |
| %for types in typeslist: | |
| % typeparam = commaSep(types + [rtype]) | |
| % functionType = '@escaping (' + commaSep(types) + ') -> ' + rtype | |
| % resulttype = ' -> '.join(['(' + s + ')' for s in types]) + ' -> ' + rtype | |
| func curry<${typeparam}>(_ f: ${functionType}) -> ${resulttype} { | |
| ${body(types)} | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment