Socket
Socket
Sign inDemoInstall

functionally

Package Overview
Dependencies
0
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    functionally

Functionally ============


Version published
Weekly downloads
822
decreased by-10.46%
Maintainers
1
Install size
59.8 kB
Created
Weekly downloads
 

Readme

Source

Functionally

Usage

npm install functionally
var F = require('functionally')

function log(msg){
    console.log(msg)
}

function greet(name){
    return 'Hello ' + name + '!'
}

var logGreeting = F.compose(log, greet)

logGreeting('Bob') //console.log('Hello Bob!')

find(fn, target)

Returns the first object in target for which fn returns a truthy value.

Example

F.find(function(obj){
    return obj.name == 'js'
}, [
    {name: 'ruby'},
    {name: 'js'},
    {name: 'php'},
    {name: 'erlang'}
])
//returns the second object in the array

The find function is curried, so you can do

var findFirst = F.find(function(value, index, target){
    if (index === 0){
        return value
    }
})

findFirst([4,5,6]) == 4

once(fn)

Returns a function that calls fn just once.

Example

var counter = 0

var inc = F.once(function(){
    counter++
})

inc()
counter == 1

inc()
inc()

counter == 1

The function returned by once returns the result of the original function. On subsequent calls, returns the same result.

maxArgs(fn, count)

If you use parseInt as the parameter to array.map, you get an undesired result

['1','2','3'].map(parseInt)
//[1, NaN, NaN]

But if you use maxArgs:

var parseInt = F.maxArgs(parseInt, 1)
['1','2','3'].map(parseInt)
//you get [1,2,3], the expected result

FAQs

Last updated on 18 Aug 2014

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc