Skip to content
/ get Public

Create functions for use with map, reduce, filter, etc. that get object properties without need for anonymous wrappers.

Notifications You must be signed in to change notification settings

timoxley/get

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

get

Create functions for use with functional methods like map, reduce, filter, etc. that get object properties without need of anonymous wrappers.

NPM

Build Status Dependency Status

Installation

Browser

$ component install timoxley/get

See Components

Node

$ npm install timoxley-get

Sorry for namespaced package, all good names taken.

Examples

Before:

Horrible anonymous wrapper is required to map the length property.

['apple', 'banana', 'pineapple'].map(function(str) {
 return str.length
})
// => [5, 6, 9]

After

Wow. Much cleaner.

['apple', 'banana', 'pineapple'].map(get('length'))
// => [5, 6, 9]

Use get to evaluate methods

// Calls the 'italics' method on each supplied item
['apple', 'banana', 'pineapple'].map(get('italics'))
// => ['<i>apple</i>', '<i>banana</i>', '<i>pineapple</i>']

Use get to evaluate methods, passing in arguments

// Calls the 'substr' method, passing in arguments
['apple', 'banana', 'pineapple'].map(get('substr', 0, 1))
// => ['a', 'b', 'p']

Convoluted Description:

Takes a property name, prop along with any number of additional arguments, and returns a function, that takes an object of any type, and returns the value of prop on that object. If prop is a method, the returned value with be the result of evaluating that method, passing in the the additional arguments.

Turns out this is hard to describe.

License

MIT

About

Create functions for use with map, reduce, filter, etc. that get object properties without need for anonymous wrappers.

Resources

Stars

Watchers

Forks

Packages

No packages published