Skip to content

alvarolorentedev/array-peek

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logomakr_5sisss

Build Status codecov npm GitHub license Maintenance Donate

extend array functionality to allow peek method.

peek vs forEach

peek as forEach allows you to execute a callback on each of the elements of an array, not affecting the content of itself.

The difference is that forEach returns void so no further processing can be done, while peek will return the array so you can continue the transformations necesary for your processing

Installation

add it to your project using npm install array-peek --save or yarn add array-peek

Usage

to use this package just add it before the usage of any array to extend its prototype. From then on you will have access to the peek function as seen in the next example.

require('array-peek')

[1,2,3]
    .peek(console.log)
    .map((value) => value * value)
    .peek(console.log)
    
//  Output:
//> 1
//> 2
//> 3
//> 1
//> 4
//> 9
Created my free logo at LogoMakr.com

About

extend array functionality to allow peek method

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published