GithubHelp home page GithubHelp logo

hg-pyun / iterize Goto Github PK

View Code? Open in Web Editor NEW
63.0 5.0 4.0 152 KB

Use JavaScript Iterator, Easily

License: MIT License

TypeScript 96.56% JavaScript 3.44%
javascript typescript generator iterator minimalistic library

iterize's Introduction

job Hits

Github Stats

iterize's People

Contributors

helloworldpark avatar hg-pyun avatar pistis avatar sungjinyoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

iterize's Issues

Add mssing guide to README.md

  1. Change Word
    generator -> Iterable protocol

  2. Add Import Guide

import * as iterize from 'iterize';
or
import { range } from 'iterize';
  1. Fixed indent
// As - Is
import { range } from 'iterize';
// To - Be
import {range} from 'iterize'; 
  1. Remove iterize word in interface
// As - Is
iterize.range
// To - Be
range

Reformat Code

When the prettier setting is done, reformatting the all codes.

Discuss 1.1.0 feature

Expected Feature List

  • Exception handling when using infinite type on cycle, repeat, replicate method.
  • Support function type.
  • Refactoring Error Models.
  • Refactoring Test Cases.
  • Discuss default parameter on range.
range(1, 10) // default step 1,
range(10, 1) // default step -1

Improve range API

Summary

Improve range API.

Feature

  • one arguments
range(5) // [0, 1, 2, 3, 4]
  • two arguments
range(1, 10) // default step 1,
range(10, 1) // default step -1

TODO

  • one arguments
  • two arguments

write spread syntax test code

A test code is required for the spread operator.
Here are some example.

example

[...range(1, 10, 1)]; // [1, 2, 3 ... 9]
[...range(1, 10, x => x + 1)]; // [1, 2, 3 ... 9]
[...range(2, 64, x => x * x)]; // [2, 4, 16]

const rangeIterator = range(1, 5, 1);
[...replicate(2, rangeIterator)]; // [1, 2, 3, 4, 1, 2, 3, 4]

Document Page

Setup document guide page.
i think it used to github.io.

Exception handling when using infinite type

Summary

cycle, repeat, replicate check the iterator param that RepeatIterator.
It is not necessary to include repetition in a function that is already repetitive.

Feature

  • Type checking the iterator parameter is RepeatIterator.

TODO

  • Make test case
  • Type checking cycle
  • Type checking repeat
  • Type checking replicate

Support log messages on dev environment.

Many libraries support logging message for easy debugging. Normally, using process.env.NODE_ENV, switching between dev and production environment. Let's talking about this.

Define Combination API

#1 Development is done.
Let's discussion combination APIs.

APIs

  • Cycle
let range = iterize.range(1, 5, 1);
cycle(range);
// 1 2 3 4 1 2 3 4 1 2 3 4 ...
  • Replicate
    Add generator type parameter
const range = iterize.range(1, 5, 1);
iterlize.replicate(2, range);
1 2 3 4 1 2 3 4 

Discuss 1.2.0 feature

Purpose

  • Add higher-API functions
  • Refactoring
  • Fixed Bugs

Ideas

  • Support string type on cycle
cycle('ABCD') --> A B C D A B C D ...
  • combine repeat and replicate api
repeat(item, count);
  • takewhile
takewhile(x => x < 5, [1,4,6,4,1]) --> 1 4
  • accumulate
accumulate([1,2,3,4,5]) --> 1 3 6 10 15
accumulate([1,2,3,4,5], operator.mul) --> 1 2 6 24 120

Discuss

Refactoring Test Cases

Summary

Current test cases are written inefficiently.

Feature

  • Reduce duplication
{ value: 0, done: false }
  • Using a repeated sentence
// refactor using 'for' syntax
it('number type', () => {                                        
    const iter = repeat(0);                                      
    expect(iter.next()).to.deep.equal({ value: 0, done: false });
    expect(iter.next()).to.deep.equal({ value: 0, done: false });
    expect(iter.next()).to.deep.equal({ value: 0, done: false });
    expect(iter.next()).to.deep.equal({ value: 0, done: false });
    expect(iter.next()).to.deep.equal({ value: 0, done: false });
});                                                              

TODO

  • Make reduce util
  • Change for syntax

Support browser version

Currently, it is built in a structure that can only be used in nodejs using the babel-runtime. For immediate use by browser via CDN, source code bundling is required. Now we're thinking about using webpack to create a version that we build separately.

Improve lazy evaluation

The parts that receive the Iterator in the replicate and cycle APIs are not exactly satisfied with the lazy evaluation. This is because an array is built internally using the spread operator.

cycle.ts

if (isGenerator) {
     cycleItem = [...item];
}

replicate.ts

if (isGenerator(item)) {
      let spreadItem = [...(item as IterableIterator<any>)];
      let iterItem: any[] = [];

      for (let i = 0; i < count; i++) {
          iterItem = iterItem.concat(spreadItem);
      }
...

Improvements are needed to evaluate dynamically using iterator.

Support Function Type

Summary

Support Function Type.

Feature

  • cycle
cycle([fn1, fn2, fn3])
  • repeat
repeat(fn);
  • replicate
replicate(3, fn);

TODO

  • Make test case
  • Type checking
  • Implement fn argument

API architecture

Description about API architecture.

APIs

  • Range
// API
range(start: number, end: number, step: number | Function): Iterator

// example
iterize.range(1, 10, 1);
iterize.range(1, 10, x => x+1);
1 2 3 ... 9
  • Cycle
// API
cycle(arr: Array<any>): Iterator

// example
iterize.cycle([1, 2, 3]);
1 2 3 1 2 3 1 2 3 1 2 ...
  • Take
// API
iterize.take(count: number, iter: Iterator): Iterator

// example
const cycle = lterize.cycle([1, 2, 3]);
iterize.take(5, cycle);
[1, 2, 3, 1, 2]
  • Repeat
// API
iterize.repeat(item: number | string): Iterator

// example
iterize.repeat(5)
5 5 5 5 5 5 5 5 ...
  • Replicate
// API
iterize.replicate(count: number, item: number | string): Iterator

// example
iterize.replicate(3, 10)
10 10 10

Reference

Write cookbook

Many library have cookbook that explain how to use it. It seems that it could make many combinations.
How about write cookbook? I attach reference ramda.

Write down API Document

Write down API Document. For now, write down the definition of api spec on README.md.
After Let's make a later API-related document.

Refactoring Error Model

Summary

There is currently overlap in the error model. It optimizes this.

Feature

Redesign Error Model.

  • Input Type Error
  • Argument Error
  • Behavior Error

TODO

  • Redesign error model.
  • Fixed test cases.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.