Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

array-mat

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

array-mat

Array concat => map rolled in a mat.

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Array concat => map rolled in a mat.

Build Status NPM Downloads



Install

npm install array-mat

Synopsis

mat takes an array A₀, a transform function F(A₀) => A₁ and returns a new array A₀ + A₁:

A.mat(F) /* ==> */ A.concat(A.map(F))

Given an array A₀ and N number of transforms A₀ + F(A₀) + ... + Fₙ(Fₙ₋₁(A))

A
  .mat(F[0])
  ...
  .mat(F[F.length - 1])

  // ==>

  A.concat(A.map(F[0]), ..., /* Aₙ₋₁ */.map(F[F.length - 1]))

Examples

["A", "B", "C"].mat((k)=>k.toLowerCase())
/* [ 'A', 'B', 'C', 'a', 'b', 'c' ] */

[].concat.apply([], ["A", "B"]
    .mat((file) => file.toLowerCase())
    .mat((file) => [file + ".js", file + ".es"]))
/*
  [
    'A','B','a','b',
    'A.js','A.es','B.js','B.es',
    'a.js','a.es','b.js','b.es'
  ]
*/

Extending the Prototype

Quoting @raynos:

Extending natives is a decision a library user should make, not a decision a library author should make.

You can extend the Array prototype like so:

Array.prototype.mat = Array.prototype.mat || require("array-mat")

console.log(
  [0]
    .mat((k) => k + 1 )
    .mat((k) => k + 2 )
    .mat((k) => k + 4 )
)

Or use as a standalone function. The return value of the first call to mat, will be an array with a non-enmurable mat method that you can use to create a chain of concat-transforms.

let mat = require("array-mat")

console.log(
  mat([0], (k) => k + 1)
    .mat((k) => k + 2)
    .mat((k) => k + 4)
)

Use node's --harmony flag for arrow function support.

» node --harmony example.js
[ 0, 1, 2, 3, 4, 5, 6, 7 ]

It's up to you. You can learn more about extending JavaScript natives here.

License

MIT © Jorge Bucaran

Keywords

FAQs

Package last updated on 29 Apr 2015

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