static <A, B> F1<A, B> codeToFunctionOnArbitraryType(S code, S type, Class<A> javaType, S varName) { code = trim(code); Class c; S methodName; if (isIdentifier(code)) { // name of standard function c = loadFunctions_cached_withInit(code); methodName = code; } else if (jcontains(code, "calc(")) { // code defines its own calc function c = veryQuickJava(code); methodName = 'calc; } else { // code is an expression or block working on variable s S main = "sO calc(final " + type + " " + varName + ") {\n" + tok_addReturn(code) + "\n}"; c = veryQuickJava(main); methodName = 'calc; } final Method m = findMethod_precise_onTypes(c, methodName, javaType); if (m == null) fail("Not a method on " + c + ": " + code + "(" + javaType + ")"); ret (F1) func(O o) -> O { invokeMethod(m, null, o) }; }
Began life as a copy of #1020643
download show line numbers debug dex old transpilations
Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1020936 |
| Snippet name: | codeToFunctionOnArbitraryType |
| Eternal ID of this version: | #1020936/4 |
| Text MD5: | 8bc6b43c92b6bdf43c6b9f05120897b6 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2019-01-17 20:26:48 |
| Source code size: | 859 bytes / 20 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 537 / 552 |
| Version history: | 3 change(s) |
| Referenced in: | [show references] |