haxetink / tink_pure

Pure immutable data.
MIT License
10 stars 7 forks source link

Better tink_json support for Mapping #9

Open kevinresol opened 6 years ago

kevinresol commented 6 years ago

Currently it is serialized as Array<MapEntry> which could be containing redundant info.

A better representation would be Map in the serialized form = Array<Tuple>

But somehow I couldn't make the compiler to accept that.

kevinresol commented 6 years ago

The code and error I have attempted is:

  @:to inline function toRepresentation():tink.json.Representation<Map<K, V>>
    return new tink.json.Representation(toMutable());

  @:from static function ofRepresentation<K, V>(rep:tink.json.Representation<Map<K, V>>):Mapping<K, V>
    return @:privateAccess ofMutable(rep.get());

Abstract Map has no @:to function that accepts IMap<tink.pure.Mapping.K, tink.pure.Mapping.V>

back2dos commented 6 years ago

Try @:extern inline ... it might work ;)

kevinresol commented 6 years ago

It works, but I have to copy ofMutable's body because somehow it is not inlined, instead it is referenced as an actual function which does not exist.