Pythonic
Python like utility functions for JavaScript: range
, enumerate
, items
, zip
and zipLongest
.
These functions return an Iterator
instance similar to Python Iterators.
This Iterator
implementation is lazy evaluated,
offers map
,
filter
,
reduce
,
some
,
every
and Symbol.asyncIterator
interfaces.
Install
npm install pythonic --save
Functions
range
; ;// 1// 2// 3 for const i of console;// 10// 15// 20 console;// 10
enumerate
; const arr = 'a' 'b';for const index value of console;// index: 0, value: a// index: 1, value: b
zip | zipLongest
; const arr1 = 'a' 'b';const arr2 = 'c' 'd' 'e';for const first second of console;// first: a, second: c// first: b, second: d for const first second of console;// first: a, second: c// first: b, second: d// first: undefined, second: e // unzipconst arrayFirst arraySecond = ...;
items
; const obj = a: 'aa' b: 'bb';for const key value of console;// key: a, value: aa// key: b, value: bb const map = 1 'one' 2 'two';for const key value of console;// key: 1, value: one// key: 2, value: two
Iterator
; const randomIntegers = { for const _ of Math;}; const randomNumbers = ; for const randomNumber of randomNumbers console;// 685// 214// 202 console;// trueconsole;// true