ferrum icon indicating copy to clipboard operation
ferrum copied to clipboard

runtime type signatures (type casting/constriction)

Open koraa opened this issue 5 years ago • 0 comments

Can we introduce type signatures using plain javascript?

Used to take all arguments to their respective types. (Use with casting functions like obj, etc…)

typedfn = (types, fn) => (...args) => fn(...map(zip(types, args), (t, v) => t(v))));
typecasg = (fn, types) => 

But typefn should correctly indicate function arity.

e.g.

addNumbers = typedfn([Number, Number], plus);
concatStrings = typedfn([String, String], plus);

This constricts arbitrary argument types by casting them into the correct type.

koraa avatar Oct 12 '20 18:10 koraa