Skip to content

runtime type signatures (type casting/constriction) #128

Open
@koraa

Description

@koraa

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions