Skip to content

Instantly share code, notes, and snippets.

@masakih
Created March 4, 2021 12:58
Show Gist options
  • Select an option

  • Save masakih/21de45479b4389e29b727487d249ac8c to your computer and use it in GitHub Desktop.

Select an option

Save masakih/21de45479b4389e29b727487d249ac8c to your computer and use it in GitHub Desktop.
これでSwiftのソースを作ってみたけどswiftcが帰ってこないw #CodePiece
%{
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