New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fp-array

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fp-array

More declarative and convenient functions than in Array.prototype

  • 1.0.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-60%
Maintainers
1
Weekly downloads
 
Created
Source

fp-array

fp-array is a group of functions to do declarative programming in a more convenient way than in Array.prototype

Build Status Standard - JavaScript Style Guide

Installation

$ npm install fp-array

Syntax

const map = require('fp-array').map
const filter = require('fp-array').filter
const reduce = require('fp-array').reduce
const arr = [...]

map(arr)
  .with(callback)
  [.and(callback2)]
  [...]
  .result()

filter(arr)
  .is(callback)
  [.and(callback2)]
  [...]
  .result()

reduce(arr, callback[, initialValue])

Examples

#map()
const arr = [1, 2, 3]
// callbacks
const increment = n => n + 1
const double = n => n * 2

map(arr)
  .with(increment)
  .and(double)
  .and(String)
  .result() // ['4', '6', '8']

arr // [1, 2, 3]
Notes
  • Iterates only one time over arr
  • Inmutable: arr has not mutated, a new Array is returned when result()
  • Declarative: Easy to read syntax
#filter()
const arr = [1, 'a', true, 6, 0, 4, undefined, 10]

const number = n => typeof n === 'number'
const greaterThan4 = n => n > 4
const even = n => n % 2 === 0

filter(arr)
  .is(number)
  .and(even)
  .and(greaterThan4)
  .result() // [6, 10]

arr // [1, 'a', true, 6, 0, 4, undefined, 10]

Same notes than before applies.

#reduce()
const arr = [1, 2, 3]
reduce(
  arr,
  (acc, currentValue) => acc + currentValue,
  5
) // 11

reduce() works exactly like the original except now is outside the Array.prototype

More examples in tests.

Have any idea ?

Open an issue or say hi on twitter: @juliomatcom

MIT Licensed

Copyright (c) 2016 Julio César Martín

Keywords

FAQs

Package last updated on 25 Feb 2017

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc