{"id":16095496,"url":"https://github.com/sz-piotr/iterable-sequence","last_synced_at":"2025-08-18T10:15:50.454Z","repository":{"id":57278451,"uuid":"104564021","full_name":"sz-piotr/iterable-sequence","owner":"sz-piotr","description":"A utility library for working with iterables in modern JavaScript and TypeScript","archived":false,"fork":false,"pushed_at":"2017-11-12T18:27:27.000Z","size":155,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-10T13:33:38.389Z","etag":null,"topics":["creating-iterables","infinite","iterables","iterator-protocol","javascript","range","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sz-piotr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-23T11:54:19.000Z","updated_at":"2018-07-11T20:08:33.000Z","dependencies_parsed_at":"2022-09-18T12:31:56.846Z","dependency_job_id":null,"html_url":"https://github.com/sz-piotr/iterable-sequence","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sz-piotr/iterable-sequence","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sz-piotr%2Fiterable-sequence","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sz-piotr%2Fiterable-sequence/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sz-piotr%2Fiterable-sequence/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sz-piotr%2Fiterable-sequence/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sz-piotr","download_url":"https://codeload.github.com/sz-piotr/iterable-sequence/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sz-piotr%2Fiterable-sequence/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270977391,"owners_count":24678689,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-18T02:00:08.743Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["creating-iterables","infinite","iterables","iterator-protocol","javascript","range","typescript"],"created_at":"2024-10-09T17:05:47.251Z","updated_at":"2025-08-18T10:15:50.431Z","avatar_url":"https://github.com/sz-piotr.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/sz-piotr/iterable-sequence.svg?branch=master)](https://travis-ci.org/sz-piotr/iterable-sequence)\n[![Coverage Status](https://coveralls.io/repos/github/sz-piotr/iterable-sequence/badge.svg?branch=master\u0026n=0)](https://coveralls.io/github/sz-piotr/iterable-sequence?branch=master)\n[![License: MIT](https://img.shields.io/github/license/mashape/apistatus.svg)](https://opensource.org/licenses/MIT)\n[![npm](https://img.shields.io/npm/v/iterable-sequence.svg)](https://www.npmjs.com/package/iterable-sequence)\n\n# Iterable Sequence\n\nA utility library for working with iterables in modern JavaScript and TypeScript.\n\n[Installation](#installation) \u0026middot;\n[Introduction](#introduction) \u0026middot;\n[API](#api)\n\n## Motivation\n\nWith the ES2015 specification came the iteration protocol allowing us to write `for..of` loops in JavaScript. However the built in language APIs do not provide some useful features that the use of the protocol enables.\n\nThe fundamental difference between working with iterables and working with arrays is that an iterable does not need an underlying data structure. This opens up the possibility for ranges, infinite Collections, data manipulation without copying entire data structures and many more.\n\n## Core features\n\n1. *Lazy* - values are computed only when they are actually used\n2. *No mutation* - functions and methods don't modify their arguments or internal state of their objects\n3. *User friendly API* - intuitive names and exhaustive documentation\n4. *Types* - the library was written in TypeScript and compiled with the `--strict` option\n\n## Installation\n\nThe library is published on npm. To use it in your own project run\n```\nnpm install --save iterable-sequence\n```\n\nThen you can use the library like so:\n```typescript\n// es2015 or TypeScript\nimport { range } from 'iterable-sequence'\n\nfor(const value of range(5)) {\n  console.log(value) // outputs: 0, 1, 2, 3, 4\n}\n```\n\n```javascript\n// es5\nvar seq = require('iterable-sequence')\n\nvar values = seq.range(5).toArray()\nconsole.log(values) // outputs: 0, 1, 2, 3, 4\n```\n\nYou can also use the provided script directly in the browser (using the following link is not recommended in production):\n```html\n\u003cscript src=\"https://rawgit.com/sz-piotr/iterable-sequence/master/lib/iterable-sequence.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  var values = seq.range(5).toArray()\n  console.log(values) // outputs: 0, 1, 2, 3, 4\n\u003c/script\u003e\n```\n\n## Introduction\n\nLet's explore some of the basic capabilities of the library. Probably the most important function provided is [`range`](#range).\n\nHere is how you would use the [`range`](#range) function for iteration:\n```typescript\nimport { range } from 'iterable-sequence'\n\nfor(const i of range(5)) {\n  console.log(i) // outputs: 0, 1, 2, 3, 4\n}\n```\n\nIf you know python this will surely look familiar. What's interesting is that like the newer versions of python the [`range`](#range) function doesn't create an array. Instead it creates an iterable object. This means that you can easily create infinite sequences:\n\n```typescript\nimport { range } from 'iterable-sequence'\n\nfor(const i of range(Infinity)) {\n  console.log(i) // outputs: 0, 1, 2, 3, 4, 5, ...\n}\n```\n\n[`range`](#range) is also versatile. You can specify the starting value and even the difference between consecutive values called `step`.\n\n```typescript\nimport { range } from 'iterable-sequence'\n\nconst from1to5 = range(1, 5) // 1, 2, 3, 4\nconst withStep = range(1, 7, 2) // 1, 3, 5\n```\n\nImagine however that it didn't have that capabilities. To achive the desired result we could use the [`map`](#map) function:\n\n```typescript\nimport { range, map } from 'iterable-sequence'\n\nconst from1to5 = map(range(4), x =\u003e x + 1) // 1, 2, 3, 4\nconst withStep = map(range(3), x =\u003e x * 2 + 1) // 1, 3, 5\n```\n\n### Sequences\n\n[`range`](#range), [`map`](#map) and most other functions of the library return a [`Sequence`](#sequence). Objects of this class have methods corresponding to the standalone functions such as [`map`](#map). Let's see this in action:\n\n```typescript\nimport { range } from 'iterable-sequence'\n\nconst from1to5 = range(4).map(x =\u003e x + 1) // 1, 2, 3, 4\nconst withStep = range(3).map(x =\u003e x * 2 + 1) // 1, 3, 5\n```\n\nThe [`Sequence`](#sequence) class is very powerful, because it can be created from many different data structures. You can use an iterable object (e.g. `range(4)`, arrays: `[1, 2, 3]`, strings: `'abc'` and many others), an array-like object (one that has numerical keys and a length property. e.g. `{ 0: 'a', 1: 'b', length: 2 }`) or even a generator function (this is what the library uses internally).\n\nA [`Sequence`](#sequence) object can also be created using the constructor:\n\n```typescript\nimport { Sequence } from 'iterable-sequence'\n\nconst mySequence = new Sequence('abc')\n```\n\nWhat else can you do with a [`Sequence`](#sequence)? How can you actually use the object? The main use case is iteration:\n\n```typescript\nimport { Sequence } from 'iterable-sequence'\n\nfor(const value of new Sequence('abc')) {\n  console.log(value) // outputs: 'a', 'b', 'c'\n}\n\nnew Sequence('abc')\n  .forEach(x =\u003e console.log(x)) // outputs: 'a', 'b', 'c'\n```\n\nYou can also convert a [`Sequence`](#sequence) to an Array or even a String. This is done using [`.toArray`](#sequencetoarray) and [`.join`](#sequencejoin):\n\n```typescript\nimport { Sequence } from 'iterable-sequence'\n\nconst array = new Sequence('abc').toArray()\nconsole.log(array) // outputs: ['a', 'b', 'c']\n\nconst string = new Sequence('abc').join('-')\nconsole.log(string) // outputs: 'a-b-c'\n```\n\n### Manipulation\n\nSo far we have only covered [`range`](#range) and [`map`](#map). This is however only a small set of the functions that the library offers. Let's look at some others.\n\nA very useful function is [`zip`](#zip). It can combine two collections[\u003csup\u003e?\u003c/sup\u003e](#collection) into a single sequence. Let's see it in action:\n\n```typescript\nimport { range } from 'iterable-sequence'\n\nconst zipped = range(2, 7)\n  .zip(range(6, 1, -1))\n\n// you can use destructuring on the values\nfor(const [a, b] of zipped) {\n  console.log(`first: ${a}, second: ${b}`)\n}\n/* Output:\nfirst: 2, second: 6\nfirst: 3, second: 5\nfirst: 4, second: 3\nfirst: 5, second: 2\n*/\n```\n\nSometimes you like your data so much you want even more of it. This is when [`repeat`](#repeat) and [`repeatValue`](#repeatvalue) shine. Their purpose is what the name suggest. They are used to create sequences with values repeated over and over:\n\n```typescript\nimport { repeat, repeatValue } from 'iterable-sequence'\n\nfor(const value of repeat([1, 2], 3)) {\n  console.log(value) // outputs: 1, 2, 1, 2, 1, 2\n}\n\nfor(const value of repeatValue('a', 3)) {\n  console.log(value) // outputs: 'a', 'a', 'a'\n}\n```\n\nBut sometimes you don't like your data that much. You would rather prefer to have less. Fortunately this library supports a family of filtering functions. Let's take a quick look at each of them:\n\n```typescript\nimport { range } from 'iterable-sequence'\n\nconst data = range(3).repeat(2) // 0, 1, 2, 0, 1, 2\n\nconst notZero = data.filter(x =\u003e x !== 0) // 1, 2, 1, 2\nconst beforeFirst2 = data.takeWhile(x =\u003e x !== 2) // 0, 1\nconst first2AndAfter = data.dropWhile(x =\u003e x !== 2) // 2, 0, 1, 2\n```\n\nHere we can see another aspect of the library. No function performs mutation. This is crutial, because we can reuse the [`Sequence`](#sequence) we have already created.\n\nWe have covered the most important features of the library. To see the list of all functions and read the detailed docs see the [API](#api) section.\n\n# API\n\n## Index\n\n- [`Collection`](#collection)\n- [`Sequence`](#sequence)\n- [`Sequence.toArray`](#sequencetoarray)\n- [`Sequence.join`](#sequencejoin)\n- [`Sequence.forEach`](#sequenceforeach)\n- [`range`](#range)\n- [`repeat`](#repeat)\n- [`repeatValue`](#repeatvalue)\n- [`zip`](#zip)\n- [`append`](#append)\n- [`map`](#map)\n- [`flatMap`](#flatmap)\n- [`filter`](#filter)\n- [`take`](#take)\n- [`takeWhile`](#takewhile)\n- [`drop`](#drop)\n- [`dropWhile`](#dropwhile)\n- [`reduce`](#reduce)\n\n## `Collection`\n\n```typescript\ntype Collection\u003cT\u003e = Iterable\u003cT\u003e | ArrayLike\u003cT\u003e | (() =\u003e Iterator\u003cT\u003e)\n```\n\nThe `Collection` type is used all across the library. Objects of this type represent a collection of values, but they can represent it in different ways. `Iterable` objects have a property `@@iterator` that allows for iteration in a `for..of` loop. `ArrayLike` objects have numeric keys and a `length` property. `() =\u003e Iterator\u003cT\u003e` is a type that denotes a generator function (created using `function*`).\n\nThe values of a collection can also be collections themselves.\n\nExamples of `Collection` objects:\n\n```typescript\nconst arrayCollection = [1, 2, 3, 4]\n\nconst stringCollection = 'abcde' // note: the values are the characters!\n\nconst arrayLikeCollection = {\n  0: true,\n  1: false,\n  2: true,\n  length: 3\n}\n\nconst generatorCollection = function* () {\n  yield [1, 2, 3, 4] // note: the array is a single value of this collection\n  yield [5, 6, 7]\n  yield [8, 9]\n  yield [10]\n}\n```\n\n\n## `Sequence`\n\n```typescript\nclass Sequence\u003cT\u003e implements Iterable\u003cT\u003e\nSequence\u003cT\u003e.constructor(collection: Collection\u003cT\u003e)\n```\n\nThe `Sequence` class is the main building block of the library. It encapsulates a `Collection` object allowing for expressing data manipulations in the form of method chaining. \n\nAn `Sequence` object is lazy. No values are computed unless you want to use them. This is because `Sequence` uses generator functions internally. This opens up the possibility for infinite seqences as they don't store their values anywhere and compute them on demand.\n\nMost `Sequence` methods have their equivalents in the form of standalone functions of the same name.\n\nTo obtain an `Sequence` just use the constructor like so:\n\n```typescript\nimport { Sequence } from 'iterable-sequence'\n\nconst sequenceFromArray = new Sequence(['a', 'b', 'c'])\nconst sequenceFromString = new Sequence('abc')\nconst sequenceFromArrayLike = new Sequence({ \n  0: 'a', \n  1: 'b', \n  2: 'c',\n  length: 3 \n})\nconst sequenceFromGenerator = new Sequence(function* () { \n  yield 'a'\n  yield 'b'\n  yield 'c' \n})\n```\n\n\n## `Sequence.toArray`\n\n```typescript\nfunction Sequence\u003cT\u003e.toArray(): T[]\n```\n\nReturn an array with the elements of this Sequence.\n\nExample:\n```typescript\nimport { Sequence } from 'iterable-sequence'\n\nconst values = new Sequence('abc').toArray()\nconsole.log(values) // outputs: ['a', 'b', 'c']\n```\n\n## `Sequence.join`\n\n```typescript\nfunction Sequence\u003cT\u003e.join(separator?: string): string\n```\n\nReturn a string formed by concatenating the string representation of the elements of this Sequence.\n\nArguments:\n* **separator**: A string that will be used between the Sequence elements. Defaults to empty string.\n\nExample:\n```typescript\nimport { Sequence } from 'iterable-sequence'\n\nconst sequence = new Sequence([1, 2, 3])\nconsole.log(sequence.join()) // outputs: '123'\nconsole.log(sequence.join('-')) // outputs: '1-2-3'\n```\n\n## `Sequence.forEach`\n\n```typescript\nfunction Sequence\u003cT\u003e.forEach(fn: (value: T, index: number) =\u003e any): void\n```\n\nFor each element of this Sequence call the supplied function with the value and index of this element.\n\nArguments:\n* **fn**: The function to call with the values and indices of the elements of this Sequence.\n\nExample:\n```typescript\nimport { Sequence } from 'iterable-sequence'\n\nconst sequence = new Sequence('xyz')\nsequence.forEach(console.log) \n/* outputs:\n  'x', 0\n  'y', 1\n  'z', 2\n*/\n```\n\n## `range`\n\n```typescript\nfunction range(end: number): Sequence\u003cnumber\u003e\nfunction range(start: number, end: number): Sequence\u003cnumber\u003e\nfunction range(start: number, end: number, step: number): Sequence\u003cnumber\u003e\n```\n\nReturn a Sequence of integers smaller than the value of the first parameter starting with the value of the second parameter. The value of the third parameter dictates the step.\n\nArguments:\n* **start**: First element of the sequence. Defaults to 0.\n* **end**: Upper limit of the sequence.\n* **step**: Difference between two consecutive elements of the Sequence. Defaults to 1.\n\nExample:\n```typescript\nimport { range } from 'iterable-sequence'\n\nconst oneArgument = range(5) // 0, 1, 2, 3, 4\nconst twoArguments = range(2, 5) // 2, 3, 4\nconst threeArguments = range(0, 7, 2) // 0, 2, 4, 6\n\nconst descending = range(5, 0, -1) // 5, 4, 3, 2, 1\nconst infinite = range(Infinity) // 0, 1, 2, 3, ...\n```\n\n\n## `repeat`\n\n```typescript\nfunction repeat\u003cT\u003e(collection: Collection\u003cT\u003e, times?: number): Sequence\u003cT\u003e\nfunction Sequence\u003cT\u003e.repeat(times?: number): Sequence\u003cT\u003e\n```\n\nReturn a Sequence whose elements are the elements of the passed collection repeated the specified number of times.\n \nArguments: \n* **collection**: A Collection whose elements will be repeated in the resulting Sequence\n* **times**: The number of times the elements are repeated. Defaults to Infinity\n\nExample:\n```typescript\nimport { repeat } from 'iterable-sequence'\n\nconst tripleABC = repeat('abc', 3).join()\nconsole.log(tripleABC) // outputs: 'abcabcabc'\n\nfor(const value of repeat([1, 2])) {\n  console.log(value) // outputs: 1, 2, 1, 2, 1, 2, ...\n}\n```\n\n\n## `repeatValue`\n\n```typescript\nfunction repeatValue\u003cT\u003e(value: T, times?: number): Sequence\u003cT\u003e\n```\n\nReturn a Sequence consisting of the supplied value repeated the specified number of times.\n\nArguments:\n* **value**: A value to repeat.\n* **times**: The number of times the value is repeated. Defaults to Infinity.\n\nExample:\n```typescript\nimport { repeatValue } from 'iterable-sequence'\n\nfor(const value of repeatValue(3, 5)) {\n  console.log(value) // outputs: 3, 3, 3, 3, 3\n}\n```\n\n\n## `zip`\n\n```typescript\nfunction zip\u003cT, U\u003e(a: Collection\u003cT\u003e, b: Collection\u003cU\u003e): Sequence\u003c[T, U]\u003e\nfunction Sequence\u003cT\u003e.zip\u003cU\u003e(collection: Collection\u003cU\u003e): Sequence\u003c[T, U]\u003e\n```\n\nReturn a Sequence whose elements are two element arrays created from the elements of the collections passed as arguments. The length of the sequence is equal to the length of the shorter collection.\n\nArguments:\n* **a**: A Collection to zip\n* **b**: A Collection to zip\n\nExample:\n```typescript\nimport { zip, range } from 'iterable-sequence'\n\nconst withIndices = zip('abc', range(Infinity)).toArray()\nconsole.log(withIndices) // outputs: [['a', 0], ['b', 1], ['c', 2]]\n\nconst withIndicesReversed = range(Infinity)\n  .zip('abc')\n  .toArray()\nconsole.log(withIndicesReversed) // outputs: [[0, 'a'], [1, 'b'], [2, 'c']]\n```\n\n\n## `append`\n\n```typescript\nfunction append\u003cT, U\u003e(first: Collection\u003cT\u003e, second: Collection\u003cU\u003e): Sequence\u003cT | U\u003e\nfunction Sequence\u003cT\u003e.append\u003cU\u003e(collection: Collection\u003cU\u003e): Sequence\u003cT | U\u003e\n```\n\nReturn a Sequence consisting of elements from the first collection followed by the elements from the second\nArguments:\n* **first** A Collection to use when forming the resulting sequence.\n* **second** A Collection to use when forming the resulting sequence.\n\nExample:\n```typescript\nimport { append, range } from 'iterable-sequence'\n\nconst combined = append('abc', range(Infinity))\nfor(const x of combined) {\n  console.log(x) // outputs: 'a', 'b', 'c', 0, 1, 2, 3, ...\n}\n```\n\n\n## `map`\n\n```typescript\nfunction map\u003cT, U\u003e(collection: Collection\u003cT\u003e, fn: (value: T, index: number) =\u003e U): Sequence\u003cU\u003e\nfunction Sequence\u003cT\u003e.map\u003cU\u003e(fn: (value: T, index: number) =\u003e U): Sequence\u003cU\u003e\n```\n\nReturn a Sequence that contains the elements created from the input collection elements.\n\nArguments:\n* **collection**: A collection to use as input.\n* **fn**: A function that produces an element of the new Sequence using an element of the old collection.\n\nExample:\n```typescript\nimport { map } from 'iterable-sequence'\n\nconst lettersDashNumbers = map('abc', (letter, index) =\u003e `${letter}-${index}`)\n  .toArray()\n\nconsole.log(lettersDashNumbers) // outputs: ['a-0', 'b-1', 'c-2']\n```\n\n\n## `flatMap`\n\n```typescript\nfunction flatMap\u003cT, U\u003e(collection: Collection\u003cT\u003e, fn: (value: T, index: number) =\u003e Collection\u003cU\u003e): Sequence\u003cU\u003e\nfunction Sequence\u003cT\u003e.flatMap\u003cU\u003e(fn: (value: T, index: number) =\u003e Collection\u003cU\u003e): Sequence\u003cU\u003e\n```\n\nReturn a Sequence that contains the elements of flattened collections created from the input collection elements.\n\nArguments:\n* **collection**: A collection to use as input.\n* **fn**: A function that produces an element of the new Sequence using an element of the old collection.\n\nExample:\n```typescript\nimport { range } from 'iterable-sequence'\n\nconst timesThenPlus = range(3, 6) // 3, 4, 5\n  .flatMap((element, index) =\u003e [element * index, element + index])\n  .toArray()\n\nconsole.log(timesThenPlus) // outputs: [0, 3, 4, 5, 10, 7]\n```\n\n## `filter`\n\n```typescript\nfunction flatMap\u003cT, U\u003e(collection: Collection\u003cT\u003e, fn: (value: T, index: number) =\u003e Collection\u003cU\u003e): Sequence\u003cU\u003e\nfunction Sequence\u003cT\u003e.flatMap\u003cU\u003e(fn: (value: T, index: number) =\u003e Collection\u003cU\u003e): Sequence\u003cU\u003e\n```\n\nReturn a Sequence that contains the elements from the input collection that satisfy the predicate.\n\nArguments:\n* **collection**: A collection to filter.\n* **predicate**: A function that tests if a value satisfies some condition.\n\nExample:\n```typescript\nimport { range } from 'iterable-sequence'\n\nconst noFours = range(6, 2, -1) // 6, 5, 4, 3\n  .filter(x =\u003e x !== 4)\n  .toArray()\n\nconsole.log(noFours) // outputs: [6, 5, 3]\n```\n\n## `take`\n\n```typescript\nfunction take\u003cT\u003e(collection: Collection\u003cT\u003e, count: number): Sequence\u003cT\u003e\nfunction Sequence\u003cT\u003e.take(count: number): Sequence\u003cT\u003e\n```\n\nReturn a Sequence that contains the first elements of the collection. The argument specifies the number of elements to take. If the length of the collection is smaller, all of the colleciton elements will be present in the resulting sequence.\n\nArguments:\n* **collection**: A collection to use as source of elements.\n* **count**: The number of elements to take.\n\nExample:\n```typescript\nimport { take } from 'iterable-sequence'\n\nconst firstLetters = take('abcdefghijklmnopqrtuvwxyz', 5).join()\nconst firstCats = take(['Garfield', 'Puss', 'Smokey'], 6).join(' and ')\n\nconsole.log(firstLetters) // outputs: 'abcde'\nconsole.log(firstCats) // outputs: 'Garfield and Puss and Smokey'\n```\n\n## `takeWhile`\n\n```typescript\nfunction takeWhile\u003cT\u003e(collection: Collection\u003cT\u003e, predicate: (value: T, index: number) =\u003e boolean): Sequence\u003cT\u003e\nfunction Sequence\u003cT\u003e.takeWhile(predicate: (value: T, index: number) =\u003e boolean): Sequence\u003cT\u003e\n```\n\nReturn a Sequence that contains the elements from the input collection that occur before the element that no longer satisfies the predicate.\n\nArguments: \n* **collection**: A collection to filter.\n* **predicate**: A function that tests if a value satisfies some condition.\n\nExample:\n```typescript\nimport { Sequence } from 'iterable-sequence'\n\nconst firstName = new Sequence('John Doe and Jane Doe')\n  .takeWhile(char =\u003e char !== ' ')\n  .join()\n\nconsole.log(firstName) // outputs: 'John'\n```\n\n## `drop`\n\n```typescript\nfunction drop\u003cT\u003e(collection: Collection\u003cT\u003e, count: number): Sequence\u003cT\u003e\nfunction Sequence\u003cT\u003e.drop(count: number): Sequence\u003cT\u003e\n```\n\nReturn a Sequence that contains the elements of the collection without the first elements. The argument specifies the number of elements to omit.\n\nArguments:\n* **collection**: A collection to use as source of elements.\n* **count**: The number of elements to omit.\n\nExample:\n```typescript\nimport { drop } from 'iterable-sequence'\n\nconst allButFirst = drop('xyz', 1).join()\nconsole.log(allButFirst) // outputs: 'yz'\n```\n\n## `dropWhile`\n\n```typescript\nfunction dropWhile\u003cT\u003e(collection: Collection\u003cT\u003e, predicate: (value: T, index: number) =\u003e boolean): Sequence\u003cT\u003e\nfunction Sequence\u003cT\u003e.dropWhile(predicate: (value: T, index: number) =\u003e boolean): Sequence\u003cT\u003e\n```\n\nReturn a Sequence that contains the elements from the input collection that occur after the first element that satisfies the predicate including that element.\n\nArguments: \n* **collection**: A collection to filter.\n* **predicate**: A function that tests if a value satisfies some condition.\n\nExample:\n```typescript\nimport { range } from 'iterable-sequence'\n\nconst result = range(4)\n  .repeat(2) // 0, 1, 2, 3, 0, 1, 2, 3\n  .dropWhile(x =\u003e x \u003c 3)\n  .toArray()\n\nconsole.log(result) // outputs: [3, 0, 1, 2, 3]\n```\n\n\n## `reduce`\n\n```typescript\nfunction reduce\u003cT\u003e(collection: Collection\u003cT\u003e, fn: (accumulator: T, value: T, index: number) =\u003e T): T\nfunction Sequence\u003cT\u003e.reduce(fn: (accumulator: T, value: T, index: number) =\u003e T): T\n```\n\nApply a function against an accumulator and each element of the Collection to reduce it to a single value.\n\nArguments: \n* **collection** A Collection whose elements will be reduces to a single value.\n* **fn** A function that uses an accumulator and an element and reduces them to a single value.\n\nExample:\n```typescript\nimport { range } from 'iterable-sequence'\n\nconst multiply = (a, b) =\u003e a * b\n\nconst factorial = n =\u003e \n  range(1, n + 1).reduce(multiply)\n\nconsole.log(factorial(3)) // outputs: 6\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsz-piotr%2Fiterable-sequence","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsz-piotr%2Fiterable-sequence","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsz-piotr%2Fiterable-sequence/lists"}