Created
March 13, 2020 19:25
-
-
Save benmerckx/7f453f9d944763de457c60cd20ac5b92 to your computer and use it in GitHub Desktop.
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 haxe.DynamicAccess; | |
using Reflect; | |
@:forward | |
abstract Merge<A: {}, B: {}>(B) { | |
public function new(a: A, b: B) { | |
final res: DynamicAccess<Dynamic> = cast {}; | |
for (field in a.fields()) res[field] = a.field(field); | |
for (field in b.fields()) res[field] = b.field(field); | |
this = cast res; | |
} | |
inline function __a(): A | |
return cast this; | |
@:op(a.b) macro static function get<A: {}, B: {}>(merge: ExprOf<Merge<A, B>>, field: String) { | |
return macro @:privateAccess $merge.__a().$field; | |
} | |
} | |
class Objects { | |
public static function merge<A: {}, B: {}>(a: A, b: B): Merge<A, B> | |
return new Merge(a, b); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment