{"id":16338989,"url":"https://github.com/phadej/lazy-seq","last_synced_at":"2025-09-10T00:33:03.788Z","repository":{"id":24852534,"uuid":"28267717","full_name":"phadej/lazy-seq","owner":"phadej","description":"Lazy sequence for JavaScript","archived":false,"fork":false,"pushed_at":"2019-11-06T17:34:19.000Z","size":27,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-11T23:53:19.900Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"myoung34/bluetoothradio","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phadej.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-12-20T13:27:24.000Z","updated_at":"2022-02-07T07:39:33.000Z","dependencies_parsed_at":"2022-08-23T07:50:57.677Z","dependency_job_id":null,"html_url":"https://github.com/phadej/lazy-seq","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phadej%2Flazy-seq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phadej%2Flazy-seq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phadej%2Flazy-seq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phadej%2Flazy-seq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phadej","download_url":"https://codeload.github.com/phadej/lazy-seq/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221840955,"owners_count":16889905,"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","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":[],"created_at":"2024-10-10T23:53:14.679Z","updated_at":"2024-10-28T14:34:20.729Z","avatar_url":"https://github.com/phadej.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lazy-seq\n\n\u003e Lazy sequences\n\n[![Build Status](https://secure.travis-ci.org/phadej/lazy-seq.svg?branch=master)](http://travis-ci.org/phadej/lazy-seq)\n[![NPM version](https://badge.fury.io/js/lazy-seq.svg)](http://badge.fury.io/js/lazy-seq)\n[![Dependency Status](https://david-dm.org/phadej/lazy-seq.svg)](https://david-dm.org/phadej/lazy-seq)\n[![devDependency Status](https://david-dm.org/phadej/lazy-seq/dev-status.svg)](https://david-dm.org/phadej/lazy-seq#info=devDependencies)\n[![Code Climate](https://img.shields.io/codeclimate/github/phadej/lazy-seq.svg)](https://codeclimate.com/github/phadej/lazy-seq)\n\n## Lazy?\n\nThe list structure could be defined as\n\n```hs\ndata Seq a = Nil | Cons a (Seq a)\n```\n\nThe `Cons` constuctor takes two arguments, so there are four different laziness variants:\n\n```hs\nCons (Strict a) (Strict (Seq a)) -- 1. fully strict\nCons (Lazy a)   (Strict (Seq a)) -- 2. lazy values\nCons (Strict a) (Lazy (Seq a))   -- 3. lazy structure\nCons (Lazy   a) (Lazy (Seq a))   -- 4. fully lazy\n```\n\nThis module implements the third variant: lazy structure, but strict values.\n\n## Example\n\n```js\nvar ones = lazyseq.cons(1, function () { return ones; });\nconsole.log(ones === ones.tail()); // true!\n```\n\n## Why?\n\nThis package is originally made to optimise shrink operations in [jsverify](http://jsverify.github.io/), a property-based testing library.\n\n## API\n\n- *nil : Seq a* \u0026mdash; Empty sequence.\n\n- *cons : (head : a, tail : Array a | Seq a | () → Array a | () → Seq a) → Seq a* : Cons a value to the front of a sequence (list or thunk).\n\n- *.isNil : Boolean* \u0026mdash; Constant time check, whether the sequence is empty.\n\n- *.toString : () → String* \u0026mdash; String representation. Doesn't force the tail.\n\n- *.length : () → Nat* \u0026mdash; Return the length of the sequene. Forces the structure.\n\n- *.toArray : () → Array a* \u0026mdash; Convert the sequence to JavaScript array.\n\n- *.fold : (z : b, f : (a, () → b) → b) → b* \u0026mdash; Fold from right.\n\n    ```hs\n    fold nil x f        = x\n    fold (cons h t) x f = f x (fold t x f)\n    ```\n\n- *.head : () → a* \u0026mdash;  Extract the first element of a sequence, which must be non-empty.\n\n- *.tail : () → Seq a* \u0026mdash; Return the tail of the sequence.\n\n    ```hs\n    tail nil        = nil\n    tail (cons h t) = t\n    ```\n\n- *.nth : (n : Nat) → a* \u0026mdash; Return nth value of the sequence.\n\n- *.take : (n : Nat) → Seq a* \u0026mdash; Take `n` first elements of the sequence.\n\n- *.drop : (n : Nat) → Seq a* \u0026mdash; Drop `n` first elements of the sequence.\n\n- *.map : (f : a → b) : Seq b* \u0026mdash; The sequence obtained by applying `f` to each element of the original sequence.\n\n- *.append : (ys : Seq a | Array a) : Seq a* \u0026mdash; Append `ys` sequence.\n\n- *.filter : (p : a -\u003e bool) : Seq a* \u0026mdash; filter using `p` predicate.\n\n- *.every : (p = identity: a -\u003e b) : b | true* \u0026mdash; return first falsy value in the sequence, true otherwise. *N.B.* behaves slightly differently from `Array::every`.\n\n- *.some : (p = identity: a -\u003e b) : b | false* \u0026mdash; return first truthy value in the sequence, false otherwise. *N.B.* behaves slightly differently from `Array::some`.\n\n- *.contains : (x : a) : bool* \u0026mdash; Returns `true` if `x` is in the sequence.\n\n- *.containsNot : (x : a) : bool* \u0026mdash; Returns `true` if `x` is not in the sequence.\n\n- *fromArray: (arr : Array a) → Seq a* \u0026mdash; Convert a JavaScript array into lazy sequence.\n\n- *singleton: (x : a) → Seq a* \u0026mdash; Create a singleton sequence.\n\n- *append : (xs... : Array a | Seq a | () → Array a | () → Seq a) → Seq a* : Append one sequence-like to another.\n\n- *iterate : (x : a, f : a → a) → Seq a* \u0026mdash; Create an infinite sequence of repeated applications of `f` to `x`: *x, f(x), f(f(x))\u0026hellip;*.\n\n- *fold : (seq : Seq a | Array a, z : b, f : (a, () → b) → b) : b* \u0026mdash; polymorphic version of fold. Works with arrays too.\n\n## Release History\n\n- **1.0.0** \u0026mdash; *2015-07-28* \u0026mdash; Stable\n  - Consider stable\n  - `singleton` constructure\n  - `.contains`, `.containsNot`, `.every` and `.some` methods\n- **0.2.0** \u0026mdash; *2015-04-21* \u0026mdash; `filter`\n- **0.1.0** \u0026mdash; *2015-03-21* \u0026mdash; `append`\n- **0.0.2** \u0026mdash; *2014-12-20* \u0026mdash; Fixed `fold`\n- **0.0.1** \u0026mdash; *2014-12-20* \u0026mdash; Initial release\n\n## Contributing\n\n- `README.md` is generated from the source with [ljs](https://github.com/phadej/ljs)\n- Before creating a pull request run `make test`, yet travis will do it for you.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphadej%2Flazy-seq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphadej%2Flazy-seq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphadej%2Flazy-seq/lists"}