Code Monkey home page Code Monkey logo

iterable-utilities's Introduction

--- # profile
who: james jensen
loc: Western Australia
age: 19
pro: * # any pronouns
--- # programming stuff
languages:
  - typescript # and js when i have to
  - rust
  - dart # back before flutter was a thing lol
  - python # sometimes
  - msg: |
      comfortable with typescript and rust,
      currently improving my haskell.
--- # other stuff
hobbies:
  - maths
  - programming (obviously)
  - linguistics
  - physics
  - philosophy
  - piano
  - msg: |
      basically, a nerd.
is_really_cool: yes 
--- # socials
mast: "@jajaperson"
igrm: "@jajaperson"
kybs: "@jajaperson"
---

Mastodon

iterable-utilities's People

Contributors

jajaperson avatar scarf005 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

scarf005

iterable-utilities's Issues

chunkify only iterates first chunk

How to reproduce

import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts"
import { chunkify } from "https://deno.land/x/[email protected]/mod.ts"

const numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
const expected = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]]

assertEquals([...chunkify(numbers, 2)], expected)

Result

error message
Uncaught AssertionError: Values are not equal:


    [Diff] Actual / Expected


    [
      [
        0,
        1,
      ],
+     [
+       2,
+       3,
+     ],
+     [
+       4,
+       5,
+     ],
+     [
+       6,
+       7,
+     ],
+     [
+       8,
+       9,
+     ],
    ]

    at assertEquals (https://deno.land/[email protected]/testing/asserts.ts:214:9)
    at <anonymous>:38:1

Reason

image

the return statement is inside the for loop, only executing it once.

provide overload for type predicates

interface Array<T> {
    /**
     * Returns the value of the first element in the array where predicate is true, and undefined
     * otherwise.
     * @param predicate find calls predicate once for each element of the array, in ascending
     * order, until it finds one where predicate returns true. If such an element is found, find
     * immediately returns that element value. Otherwise, find returns undefined.
     * @param thisArg If provided, it will be used as the this value for each invocation of
     * predicate. If it is not provided, undefined is used instead.
     */
    find<S extends T>(predicate: (value: T, index: number, obj: T[]) => value is S, thisArg?: any): S | undefined
    find(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): T | undefined
}

(code from https://github.com/microsoft/TypeScript/blob/4d5ba0316a43ea31c41c50e4d62756659ddffbaa/src/lib/es2015.core.d.ts#L1-L12)

functions like find and filter should be able to utilize type predicates.

Todo

Overloads

  • find
  • filter
  • every
  • takeWhile
  • dropWhile

handle curryIterFunction

related:

Methods should not be generator functions

Using generator functions means that an iterable can only be used once. To demonstrate

function* generator() {
  let index = 0;
  while (true) {
    yield index++;
  }
}

const g = generator()

g.next().value // 0
g.next().value // 1
g[Symbol.iterator]().next().value // 2

Instead, methods should be generator functions that return an object with the iterable protocol.

feature parity with kotlin and deno stdlib collections

https://deno.land/std/collections/mod.ts
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.sequences/

Functions for specific common tasks around collection types like Array and Record. This module is heavily inspired by kotlins stdlib.

TODO

  • #10
  • ascend
  • associateBy
  • associateWith
  • chunk
  • descend
  • distinct
  • distinctBy
  • dropLastWhile
  • dropWhile
  • findSingle
  • firstNotNullishOf
  • groupBy
  • intersect
  • joinToString
  • mapNotNullish
  • maxBy
  • maxOf
  • maxWith
  • minBy
  • minOf
  • minWith
  • partition
  • permutations
  • runningReduce
  • sample
  • slidingWindows
  • sortBy
  • sumOf
  • takeLastWhile
  • takeWhile
  • union
  • unzip
  • withoutAll
  • zip

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.