unary

Creates a unary function wrapper which extracts a specific argument by index and applies the argument to the original unary function.

Usage no npm install needed!

<script type="module">
  import unary from 'https://cdn.skypack.dev/unary';
</script>

README

unary

Creates a unary function wrapper which extracts a specific argument by index and applies the argument to the original unary function.

Build Status Code Climate js-standard-style

npm install unary --save
npm stats

npm NPM downloads Dependency Status

Examples

require
var unary = require('unary')
full application
var odds = unary(odd, 1)
var fruit = [ 'apple', 'pear', 'pineapple', 'strawberry', 'orange', 'grapefruit' ]

fruit.filter(odds)
//=> [ 'apple', 'pineapple', 'orange' ]
functor (+ partial application)
var evens = unary(even)
var fruit = [ 'apple', 'pear', 'pineapple', 'strawberry', 'orange', 'grapefruit' ]

fruit.filter(evens(1))
//=> [ 'pear', 'strawberry', 'grapefruit' ]

API

unary(fun, idx)

arguments
  • fun: (Function) Unary function to wrap.
  • idx: (Number) Index of argument to extract.
returns
  • (Function) Wrapped unary function.

License

GitHub license