Giter Club home page Giter Club logo

haxe-thingies's Introduction

Haxe Thingies

This repo contains several useful little types and macros for Haxe that may or may not ease developer's life. See the code or unit tests to get the idea how and when to use these.

DynamicObject

This type wraps Reflect field access for dynamic structures in a Map-like interface, making it easier to work with JSON or external JavaScript objects.

NOTE: this abstract is now part of Haxe standard library (since 3.2.0), see https://github.com/HaxeFoundation/haxe/blob/development/std/haxe/DynamicAccess.hx

var d:DynamicObject<Int> = haxe.Json.parse('{"item1": 1, "item2": 2}');
for (key in d.keys())
    trace(d[key]);

is equivalent to

for (key in Reflect.fields(d))
    trace((Reflect.field(d, key) : Int));

OptionalField

This type provides explicit, but convenient syntax for working with optional and potentially missing structure fields, wrapping Reflect.hasField calls.

var house:{?tennant:OptionalField<String>} = {};
var tennant = house.tennant.or("Ghosts");

is equvalent to

var tennant = Reflect.hasField(house, "tennant") ? house.tennant : "Ghosts";

Unpack

This is a using-macro implementing CoffeeScript-like value destructuring (http://coffeescript.org/#destructuring).

var value = [{f: [1, 2, 3]}, {f: [1]}, {f: [1]}, {f: []}];
value.unpackInto({f: v1}, {f: [v2]}, _, {f: {length: v3}});

This unpacks arrays and object fields into local variables similar to pattern-matching, but with shorter syntax. In the example above, there will be 3 variables generated: v1, capturing [1, 2, 3], v2 capturing 1 and v3 capturing 0.

Yet to add

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.