This library is for annotating functions using Refract. The idea is the provide types for both the inputs and outputs for a given function and check those types when the function is executed.
This library is a plugin for Minim and requires Minim to be installed.
npm install minim-typed
This plugin is loaded like any Minim plugin would be loaded.
var minim = ;var minimTyped = ;// Load the pluginvar namespace = minim;
All functions for typed Minim are added to the namespace instance.
Checking a Value
The default function is the identity function. This means if you want to check the type of a value, you need to annotate both the input and output of that value as being the same type. Once this is done, you can check the type of simple values.
var stringChecker = namespacetyped;; // Returns 'foobar'; // Throws TypeError
Typed Minim is only used for annotating functions, and though the identity function is default, you may provide any function you like.
var sum = namespacetyped;; // Returns 6; // Throws TypeError
This solves question one of Project Euler with typed functions.
Find the sum of all the multiples of 3 or 5 below 1000.
var _ = ;var minim = ;var minimTyped = ;var annotate = annotate;var namespace = minim;var divBy = namespacetyped;var divBy3or5 = namespacetyped;var sum = namespacetyped;var take = namespacetyped;var answer =;console;
This code is licensed under the MIT license.