Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fantasy-environment

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fantasy-environment

Environment library which is used by Fantasy World

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
918
increased by2522.86%
Maintainers
1
Weekly downloads
 
Created
Source

Fantasy Environment

An environment holds methods and properties.

Methods are implemented as multi-methods, which allow a form of ad-hoc polymorphism. Duck typing is another example of ad-hoc polymorphism, but only allows a single implementation at a time, via prototype mutation.

A method instance is a product of a name, a predicate and an implementation:

   var env = environment()
       .method(
           // Name
           'negate',
           // Predicate
           function(n) {
               return typeof n == 'number';
           },
           // Implementation
           function(n) {
               return -n;
           }
       );

   env.negate(100) == -100;

We can now override the environment with Some more implementations:

   var env2 = env
       .method(
           'negate',
           function(b) {
               return typeof b == 'boolean';
           },
           function(b) {
               return !b;
           }
       );

   env2.negate(100) == -100;
   env2.negate(true) == false;

Environments are immutable; references to env won't see an implementation for boolean. The env2 environment could have overwritten the implementation for number and code relying on env would still work.

Properties can be accessed without dispatching on arguments. They can almost be thought of as methods with predicates that always return true:

   var env = fantasy.environment()
       .property('name', 'Fantasy');

   env.name === 'Fantasy';

Testing

Library

Fantasy Environment uses nodeunit for all the tests and because of this there is currently an existing adapter in the library to help with integration between nodeunit and Fantasy Environment.

Coverage

Currently Fantasy Environment is using Istanbul for code coverage analysis; you can run the coverage via the following command:

This assumes that you have istanbul installed correctly.

istanbul cover nodeunit -- test/*.js

It should report that the total coverage is at 100% (branches at 80.95%) for the whole lib.

FAQs

Package last updated on 29 Oct 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc