fairmont-multimethods
Functional reactive programming in JavaScript
Last updated 9 years ago by dyoder .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ npm install fairmont-multimethods 
SYNC missed versions from official npm registry.

Fairmont-Multimethods

Fairmont-Multimethods is a JavaScript library providing support for multimethods in JavaScript.

Installation

npm i -S fairmont-multimethods

Usage


equal = Method.create
  description: "'Deep' equality operator"
  default: (a, b) -> a == b # fallback to shallow equality

# when comparing objects, recursively check the values
# corresponding to the union of their properties—
# return false on the first inequality
Method.define equal, isObject, isObject, (a, b) ->
  (a == b) || do ->
    keys = new Set (Object.keys a)..., (Object.keys b)...
    for key from keys
      if ! equal a[key], b[key]
        return false
    true

# when comparing arrays, recursively check values
# after making sure they're the same length
# return false on the first inequality
Method.define equal, isArray, isArray, (ax, bx) ->
  (ax == bx) || do ->
    return false if ax.length != bx.length
    for i in [0..ax.length]
      if !equal ax[i], bx[i]
        return false
    true

equal "this", "this"  # => true, shallow equality works here
equal { x: 1, y: 2 }, { x: 1, y: 2 } # => true, deep equality
equal [1..5], [1..5] # true, deep equality
equal { x: 1, y: 2}, [1..5] # false

API documentation.

Current Tags

  • 2.0.2                                ...           latest (7 years ago)

9 Versions

  • 2.0.2                                ...           7 years ago
  • 2.0.1                                ...           7 years ago
  • 2.0.0                                ...           7 years ago
  • 1.0.1                                ...           9 years ago
  • 1.0.0                                ...           9 years ago
  • 1.0.0-beta-21                                ...           9 years ago
  • 1.0.0-beta-20                                ...           9 years ago
  • 1.0.0-beta-19                                ...           9 years ago
  • 1.0.0-beta-18                                ...           9 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE