# functionally

> Functionally - A utility belt for functional JavaScript

Latest version **0.6.2** (published 2014-10-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install functionally
pnpm add functionally
yarn add functionally
bun add functionally
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.2 |
| Published | 2014-10-22 |
| First published | 2014-07-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Radu Brehar |
| Maintainers | radubrehar |
| Keywords | functional, functionally, map, reduce, fn, pure, functions |

## Links

- npm: https://www.npmjs.com/package/functionally
- Repository: https://github.com/radubrehar/functionally
- Issues: https://github.com/radubrehar/functionally/issues
- npm.io page: https://npm.io/package/functionally

## Dependencies (1)

- [newify](https://npm.io/package/newify.md) ~1.1.9

## Recent versions

- 0.6.2 (latest) — 2014-10-22
- 0.6.1 — 2014-10-07
- 0.6.0 — 2014-10-03
- 0.5.1 — 2014-09-10
- 0.5.0 — 2014-09-08
- 0.4.1 — 2014-08-21
- 0.4.0 — 2014-08-21
- 0.3.2 — 2014-08-18
- 0.3.1 — 2014-08-13
- 0.3.0 — 2014-08-13
- 0.2.1 — 2014-08-04
- 0.2.0 — 2014-07-24
- 0.1.0 — 2014-07-24
- 0.0.5 — 2014-07-03
- 0.0.4 — 2014-07-03
- … 3 more at https://npm.io/package/functionally/versions

## README

Functionally - A utility belt for functional JavaScript

# Install

```sh
$ npm install functionally
```

# Usage

```js
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!')

```

# API

## find(fn, target)

Returns the first object in target for which fn returns a truthy value.

Example

```js
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
```js
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

```js
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
```js
['1','2','3'].map(parseInt)
//[1, NaN, NaN]
```
But if you use maxArgs:

```js
var parseInt = F.maxArgs(parseInt, 1)
['1','2','3'].map(parseInt)
//you get [1,2,3], the expected result
```

## newify(fn, [...args...])

Creates a new curried function that calls the given fn with the new operator. Expected args are the fn to use for calling new and an array of args to be used (they will be spread on the new call).

Example:
```js
function Developer(name, language){
    this.name = name
    this.lang = language
}

var newDev = newify(Developer)

var dev = newDev(['bob', 'js'])
var dev2 = newify(Developer, ['john', 'c#'])

dev instanceof Developer === true
dev2 instanceof Developer === true
```

---
_Source: https://npm.io/package/functionally · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
