cook

unified constructors
https://codeberg.org/ohmrun/cook

To install, run:

haxelib install cook 0.1.0 

See using Haxelib in Haxelib documentation for more information.

README.md

Cook

Unified Constructors for Haxe

Usage

using cook.Core;

function main(){
  final b = TestClass.cook();//By convention the type uses it's own name to put it's constructors in
  $type(b);
  final c = OtherTestClass.cook();
  final d = b.cons(c);
  $type(d);
  
  d.OtherTestClass.one().apply()
}


class TestClass{
  public function new(o:String){

  }
  static public inline function cook(){
    return Assoc.lift({ TestClass : Cook.pure(main) });
  }
  static public function main(o:{ ?v:Int }){
    return new TestClass('${o.v}');
  }

class OtherTestClass{
  public function new(o:{q: String}){

  }
  static public inline function cook(){
    return Assoc.lift({
      OtherTestClass : Cook.pure(main).cons(mainI)
    });
  }
  static public function main(o:{ q:String }){
    return new OtherTestClass(o);
  }
  static public function mainI(o : Int){
    return new OtherTestClass({ q : '$o'});
  }
}

The two main class are Assoc and Cook

Assoc

Assoc produces a well typed combination of two structural (typedef'ed or anon) types.

{ a : Int } cons {b : String } == { a : Int, b : String }

In this case we use them to grow a reference tree.

{ TypeName : ...constructors } cons { OtherTypeName : ...constructors }

Cook

Cook is a tuple of constructor functions (Partial), also connected by a cons function.

Cook is a stack, retrieves the last added constructor first.

in final ctrs = a.cons(b).cons(c), a can be reached by ctrs.two() and called ctrs.two().apply(...args) c is reached with ctrs.zero `

Partial

Partial is a wrapper for a constructor function with one argument, a structural type of some shape. It's not defined like that becauase the typing would be complex, but the cons function on it is.

Contributors
0b1kn00b
Version
0.1.0
Published
8 weeks ago
License
Public

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub