All Projects → keyvan-m-sadeghi → pythonic

keyvan-m-sadeghi / pythonic

Licence: MIT license
Python like utility functions for JavaScript: range, enumerate, zip and items.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to pythonic

dart-more
More Dart — Literally.
Stars: ✭ 81 (+189.29%)
Mutual labels:  functional, utilities
Date Fns
⏳ Modern JavaScript date utility library ⌛️
Stars: ✭ 27,650 (+98650%)
Mutual labels:  modules, utilities
transmute
kind of like lodash but works with Immutable
Stars: ✭ 35 (+25%)
Mutual labels:  functional, utilities
Lodash
A modern JavaScript utility library delivering modularity, performance, & extras.
Stars: ✭ 51,659 (+184396.43%)
Mutual labels:  modules, utilities
Gr8
Customizable, functional css utilities
Stars: ✭ 169 (+503.57%)
Mutual labels:  functional, utilities
Fxjs
Functional Extensions Library for JavaScript
Stars: ✭ 202 (+621.43%)
Mutual labels:  functional, utilities
tcl-modules
A collection of pure Tcl, production-ready micro packages
Stars: ✭ 25 (-10.71%)
Mutual labels:  modules, utilities
fnts
λ Minimal Functional Programming Utilities for TypeScript & JavaScript
Stars: ✭ 75 (+167.86%)
Mutual labels:  functional
lambda-zero
A minimalist pure lazy functional programming language
Stars: ✭ 65 (+132.14%)
Mutual labels:  functional
dotfiles
.foos for foos & more
Stars: ✭ 21 (-25%)
Mutual labels:  utilities
OregonCore-Modules
Modules made for Oregoncore
Stars: ✭ 18 (-35.71%)
Mutual labels:  modules
grand central
State-management and action-dispatching for Ruby apps
Stars: ✭ 20 (-28.57%)
Mutual labels:  functional
Fae
A functional module for Deno inspired from Ramda.
Stars: ✭ 44 (+57.14%)
Mutual labels:  functional
tcpview
TcpView For Linux
Stars: ✭ 62 (+121.43%)
Mutual labels:  utilities
JEval
⚡ JEval helps you to evaluate your JMeter test plan and provides recommendation before you start your performance testing. All contributions welcome 🙏.
Stars: ✭ 28 (+0%)
Mutual labels:  utilities
SeLite
Automated database-enabled navigation ✔️ of web applications
Stars: ✭ 34 (+21.43%)
Mutual labels:  functional
laravel-admin
Laravel Admin panel with theme , modules ,artisan commands and helper classess.Laravel admin boilerplate with theme and modules
Stars: ✭ 22 (-21.43%)
Mutual labels:  modules
vade-mecum-shelf
Collection of vade mecum-like utilities wrapped into one single app, built with Electron.
Stars: ✭ 33 (+17.86%)
Mutual labels:  utilities
java-modern-tech-practice
😎 Java™ modern tech practice sandbox ⏳
Stars: ✭ 43 (+53.57%)
Mutual labels:  functional
StartupModules
Startup modules for ASP.NET Core.
Stars: ✭ 33 (+17.86%)
Mutual labels:  modules

npm version Build Status

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

import {range} from 'pythonic';

range(3).map(x => console.log(x + 1));
// 1
// 2
// 3

for (const i of range(10, 25, 5))
    console.log(i);
// 10
// 15
// 20

console.log(range(5).reduce((accumulator, current) => accumulator + current));
// 10

enumerate

import {enumerate} from 'pythonic';

const arr = ['a', 'b'];
for (const [index, value] of enumerate(arr))
    console.log(`index: ${index}, value: ${value}`);
// index: 0, value: a
// index: 1, value: b

zip | zipLongest

import {zip, zipLongest} from 'pythonic';

const arr1 = ['a', 'b'];
const arr2 = ['c', 'd', 'e'];
for (const [first, second] of zip(arr1, arr2))
    console.log(`first: ${first}, second: ${second}`);
// first: a, second: c
// first: b, second: d

for (const [first, second] of zipLongest(arr1, arr2))
    console.log(`first: ${first}, second: ${second}`);
// first: a, second: c
// first: b, second: d
// first: undefined, second: e

// unzip
const [arrayFirst, arraySecond] = [...zip(...zip(arr1, arr2))];

items

import {items} from 'pythonic';

const obj = {a: 'aa', b: 'bb'};
for (const [key, value] of items(obj))
    console.log(`key: ${key}, value: ${value}`);
// key: a, value: aa
// key: b, value: bb

const map = new Map([[1, 'one'], [2, 'two']]);
for (const [key, value] of items(map))
    console.log(`key: ${key}, value: ${value}`);
// key: 1, value: one
// key: 2, value: two

Iterator

import {Iterator, range} from 'pythonic';

const randomIntegers = (size, start, stop) => new Iterator(function * () {
    for (const _ of range(size))
        yield Math.floor(Math.random() * (stop - start) + start);
});

const randomNumbers = randomIntegers(3, 10, 1000);

for (const randomNumber of randomNumbers)
    console.log(randomNumber);
// 685
// 214
// 202

console.log(randomNumbers.some(value => value > 10));
// true
console.log(randomNumbers.every(value => value < 1000));
// true

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].