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

fn-pasta

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fn-pasta - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

14

fn-pasta.js

@@ -37,2 +37,12 @@ // pasta.js

function memo (fn, cache) {
cache = memoed._cache = cache || {}
function memoed () {
var args = JSON.stringify(p.slice(arguments))
if (!(args in cache)) cache[args] = fn.apply(this, arguments)
return cache[args]
}
return memoed
}
var numOfArgs =

@@ -47,3 +57,3 @@ { '1': function (fn) { return function (a) { return fn(a) } }

return function () {
return fn.apply(null, p.slice(arguments).slice(0, num))
return fn.apply(null, p.slice(arguments, 0, num))
}

@@ -127,2 +137,4 @@ }

, all: all
, memo: memo
, memoize: memo
}

@@ -129,0 +141,0 @@

2

package.json
{ "name": "fn-pasta"
, "version": "0.0.4"
, "version": "0.0.5"
, "author": "Nick Niemeir <nick.niemeir@gmail.com> (http://nrn.io)"

@@ -4,0 +4,0 @@ , "main": "fn-pasta.js"

@@ -38,2 +38,9 @@ Functional Pasta

memo(fn[, cache])
-----------------
Return a memoized version of fn, with \_cache attached. Can provide
an optional starting cache (be careful, can be used to provide incorrect
answers to function calls). Cache keys are the stringified array of arguments.
op(operator)

@@ -40,0 +47,0 @@ ------------

@@ -49,7 +49,21 @@ var p = require('../fn-pasta')()

t.equal(p.curry(add)(1)(1), 2, 'Curry default')
t.equal(p.curry(sum, 5)(1)(2)(3)(4)(5), 15, 'Curry 5 times')
var called = 0
var memoAdd = p.memo(function (a, b) {
called++
t.same(called, 1, 'Only called once')
return add(a, b)
})
var memoSum = p.memo(sum, { '["broken",2]': 'Surprise!' })
t.same(memoAdd(1, 2), 3, 'First memo call')
t.same(memoAdd(1, 2), 3, 'Second memo call')
t.same(memoAdd(1, 2), 3, 'Third memo call')
t.same(memoSum('broken', 2), 'Surprise!', 'Provided cache object')
t.same(memoSum(1, 1), 2, 'Avoid cache object')
t.same(memoSum._cache, { '["broken",2]': 'Surprise!', '[1,1]': 2 }, 'Check cache')
t.end()
})
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