Skip to content

Commit

Permalink
Upgrade lazyjs to latest release
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed Sep 7, 2018
1 parent 238ad0d commit a801aaa
Show file tree
Hide file tree
Showing 125 changed files with 1,477 additions and 519 deletions.
7 changes: 0 additions & 7 deletions lib/lazy.js-0.4.0/.travis.yml

This file was deleted.

2 changes: 0 additions & 2 deletions lib/lazy.js-0.4.0/lazy.min.js

This file was deleted.

22 changes: 0 additions & 22 deletions lib/lazy.js-0.4.0/spec/es6_spec.js

This file was deleted.

File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions lib/lazy.js-0.5.1/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
sudo: false

language: node_js

node_js:
- "0.10"
- "0.12"
- 4
- 6
- 7

install:
- npm install
46 changes: 46 additions & 0 deletions lib/lazy.js-0.4.0/CHANGES.md → lib/lazy.js-0.5.1/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,53 @@ Lazy.js Changelog

This file includes at least a partial list of the major changes in each version.

Unreleased
----------

- added public `equals()` method (#139)
- added public `Lazy.curry` and `Lazy.curryRight` methods (#24)
- added public `Lazy.createCallback` and `Lazy.createComparator` methods (#140)
- added shallow option to `flatten()` (#125)
- added equalityFn paramter to `indexOf`, `lastIndexOf`, and `contains`
- fixed bug with return value from `consecutive()` not being reusable (#212)
- fixed bug with `concat()` unexpectedly flattening results (#127)

v0.5.0
------

- sequences now support ES6 [iterable protocol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) (#186)
- added support for ES6 [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) and [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) objects
- `memoize().get` no longer iterates entire sequence (#191)
- fixed bug causing failure on `defaults().defaults()` (#183)
- fixed bug with setting encoding in `Lazy.readFile` (#160)

v0.4.3
------

- added `push` and `unshift` to `ArrayLikeSequence` (#173)
- changed behavior of `min` and `max` to return `undefined` for empty sequences (#194)
- made `zip` and `intersection` communicative (#196 and #197)
- fixed bug w/ shuffling empty array returning `[undefined]` (#198)
- added support for non-string delimiters in `join` (#193)
- fixed bug w/ missing return value in full iteration of `groupBy` (#179)
- fixed bug w/ ignoring delimiter in `values().join` (#184)
- fixed behavior of `ObjectLikeSequence.keys` (#164)
- fixed broken `DomEventSequence.each` (#163)
- fixed handling of falsey values in `get` (#170)
- changed behavior of `ObjectLikeSequence.each` (see #165)

v0.4.2
------

- dropped support for node 0.8
- Lazy is now exposed as a UMD module
- added value transform function to `groupBy`/`indexBy` ([#97](https://github.com/dtao/lazy.js/pull/97))
- fixed biased implementation of `shuffle` (see [#142](https://github.com/dtao/lazy.js/pull/142))
- fixed bug where `split` couldn't be called on `StringSegments` (see [#123](https://github.com/dtao/lazy.js/pull/123))
- fixed `merge` to better handle arrays, dates, and other object types (see [#154](https://github.com/dtao/lazy.js/pull/154))

v0.4.0
------

- now `Lazy.AsyncHandle` implements the Promises/A+ specification! (see [#71](https://github.com/dtao/lazy.js/issues/71))
- made `Sequence#get` available to all sequences, not just `ArrayLikeSequence`s (see [#106](https://github.com/dtao/lazy.js/issues/106))
Expand Down
53 changes: 53 additions & 0 deletions lib/lazy.js-0.5.1/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
Running the tests
-----------------

Lazy.js has a bunch of tests. They run in Node as well as the browser. To test against Node:

```
npm test
```

To test against the browser, the easiest method is to just build the site and open it up.

How to build the site
---------------------

The build process for the site is horrendously complicated right now. I'm going to do something about that some day, but today is not that day. In the meantime, here are at least some instructions for how to do it (this is mainly for myself, so that I don't have to job my memory every time I do this).

First:

```
cd site
```

Install requirements (if necessary):

```
npm install -g deft
bundle install
```

Pull in front-end dependencies using deft:

```
deft
```

Now build the site using middleman:

```
middleman build
```

(At this point I hand-delete the bower package and npm package badges in the resulting site/build/index.html file. Yes, seriously. Don't judge me.)

*Now*, head back to the lazy.js root directory, create symlinks, and generate the API docs:

```
rake symlinks
rake generate_docs
```

Finally, to publish the new site, tar up everything in the build folder, run `git checkout gh-pages`, extract the archive, and push the changes up.

It's *that* simple.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014 Dan Tao
Copyright (c) 2014—2018 Dan Tao

MIT License

Expand Down
67 changes: 25 additions & 42 deletions lib/lazy.js-0.4.0/README.md → lib/lazy.js-0.5.1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ Like Underscore, but lazier
[![Bower version](https://badge.fury.io/bo/lazy.js.svg)](http://badge.fury.io/bo/lazy.js)
[![NPM version](https://badge.fury.io/js/lazy.js.svg)](http://badge.fury.io/js/lazy.js)

**Lazy.js** is a functional utility library for JavaScript, similar to [Underscore](http://underscorejs.org/) and [Lo-Dash](http://lodash.com/), but with an underlying engine that supports many more use cases than those libraries, while offering comparable or superior performance in most scenarios.
Lazy.js is a functional utility library for JavaScript, similar to [Underscore](http://underscorejs.org/) and [Lodash](http://lodash.com/), but with a **lazy engine** under the hood that strives to do as little work as possible while being as flexible as possible.

The following chart illustrates the performance of Lazy.js versus Underscore and Lo-Dash for several common operations using arrays with 10 elements each on Chrome 39:
It has no external dependencies, so you can get started right away with:

![Lazy.js versus Underscore/Lo-Dash](http://i.imgur.com/9vP6sVG.png)

You can see that the performance difference becomes much more significant for methods that don't require iterating an entire collection (e.g., `indexOf`, `take`) as the arrays get larger:
```javascript
npm install lazy.js
```

![Lazy.js versus Underscore/Lo-Dash](http://i.imgur.com/oGPlPug.png)
(Note the package is called "lazy.js", with a dot.)

Intrigued? Great! Lazy.js has no external dependencies, so you can get started right away with:
Or, if you're using Lazy.js in the browser:

```html
<script type="text/javascript" src="lazy.js"></script>
Expand All @@ -24,12 +24,6 @@ Intrigued? Great! Lazy.js has no external dependencies, so you can get started r
<script type="text/javascript" src="lazy.browser.js"></script>
```

Or, if you're using Node.js:

```bash
npm install lazy.js
```

Now let's look at what you can do with Lazy.js. (For more thorough information, take a look at the [API Docs](http://dtao.github.io/lazy.js/docs/).)

Introduction
Expand All @@ -41,7 +35,7 @@ Let's start with an array of objects representing people.
var people = getBigArrayOfPeople();
```

Now let's suppose we're using this array to back some sort of search-as-you-type functionality, where users can search for people by their last names. Naturally we want to put some reasonable constraints on our problem space, so we'll provide up to 5 results at a time. Supposing the user types "Smith", we could therefore fetch results using something like this (using Underscore):
Suppose we're using this array to back some sort of search-as-you-type functionality, where users can search for people by their last names. Naturally we want to put some reasonable constraints on our problem space, so we'll provide up to 5 results at a time. Supposing the user types "Smith", we could therefore fetch results using something like this (using Underscore):

```javascript
var results = _.chain(people)
Expand All @@ -62,9 +56,8 @@ So if performance and/or efficiency were a concern for you, you would probably *
```javascript
var results = [];
for (var i = 0; i < people.length; ++i) {
var lastName = people[i].lastName;
if (lastName.startsWith('Smith')) {
results.push(value);
if (people[i].lastName.startsWith('Smith')) {
results.push(people[i].lastName);
if (results.length === 5) {
break;
}
Expand All @@ -74,7 +67,7 @@ for (var i = 0; i < people.length; ++i) {

There&mdash;now we haven't created any extraneous arrays, and we did all of the work in one iteration. Any problems?

Well, yeah. The main problem is that this is one-off code, which isn't reusable and took a bit of time to write. If only we could somehow leverage the expressive power of Underscore but still get the performance of the hand-written procedural solution...
Well, yeah. The main problem is that this is one-off code, which isn't reusable or particularly readable. If only we could somehow leverage the expressive power of Underscore but still get the performance of the hand-written procedural solution...

***

Expand All @@ -87,18 +80,18 @@ var result = Lazy(people)
.take(5);
```

Looks almost identical, right? That's the idea: Lazy.js aims to be completely familiar to experienced JavaScript devs. Every method from Underscore should have the same name and (almost) identical behavior in Lazy.js, except that instead of returning a fully-populated array on every call, it creates a *sequence* object with an `each` method.
Looks almost identical, right? That's the idea: Lazy.js aims to be completely familiar to JavaScript devs experienced with Underscore or Lodash. Every method from Underscore should have the same name and (almost) identical behavior in Lazy.js, except that instead of returning a fully-populated array on every call, it creates a *sequence* object with an `each` method.

What's important here is that **no iteration takes place until you call `each`**, and **no intermediate arrays are created**. Essentially Lazy.js combines all query operations into a sequence that behaves quite a bit like the procedural code we wrote a moment ago. (If you ever *do* want an array, simply call `toArray` on the resulting sequence.)
What's important here is that **no iteration takes place until you call `each`**, and **no intermediate arrays are created**. Essentially Lazy.js combines all query operations into a "sequence" that behaves quite a bit like the procedural code we wrote a moment ago. (If you ever *do* want an array, simply call `toArray` on the resulting sequence.)

Of course, *unlike* the procedural approach, Lazy.js lets you keep your code clean and functional, and focus on building an application instead of optimizing array traversals.
Of course, *unlike* the procedural approach, Lazy.js lets you keep your code clean and functional, and focus on solving whatever problem you're actually trying to solve instead of optimizing array traversals.

Features
--------

So, Lazy.js is basically Underscore with lazy evaluation. Is that it?

Of course not!
Nope!

### Indefinite sequence generation

Expand All @@ -107,13 +100,11 @@ The sequence-based paradigm of Lazy.js lets you do some pretty cool things that
Here's an example. Let's say we want 300 unique random numbers between 1 and 1000.

```javascript
var uniqueRandsFrom1To1000 = Lazy.generate(Math.random)
Lazy.generate(Math.random)
.map(function(e) { return Math.floor(e * 1000) + 1; })
.uniq()
.take(300);

// Output: see for yourself!
uniqueRandsFrom1To1000.each(function(e) { console.log(e); });
.take(300)
.each(function(e) { console.log(e); });
```

Here's a slightly more advanced example: let's use Lazy.js to make a [Fibonacci sequence](http://en.wikipedia.org/wiki/Fibonacci_number).
Expand All @@ -130,9 +121,6 @@ var fibonacci = Lazy.generate(function() {
};
}());

// Output: undefined
var length = fibonacci.length();

// Output: [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
fibonacci.take(10).toArray();
```
Expand All @@ -141,26 +129,21 @@ OK, what else?

### Asynchronous iteration

You've probably [seen code snippets before](https://gist.github.com/dtao/2351944) that show how to iterate over an array asynchronously in JavaScript. But have you seen an example packed full of map-y, filter-y goodness like this?
You've probably [seen code snippets before](https://gist.github.com/dtao/2351944) that show how to iterate over an array asynchronously in JavaScript. But have you seen an example with functional goodness like this?

```javascript
var asyncSequence = Lazy(array)
.async(100) // specifies a 100-millisecond interval between each element
.map(inc)
.filter(isEven)
.take(20);

// This function returns immediately and begins iterating over the sequence asynchronously.
asyncSequence.each(function(e) {
console.log(new Date().getMilliseconds() + ": " + e);
});
Lazy.generate(Lazy.identity)
.async(1000) // specifies a 1-second interval between each element
.map(function(x) { return String.fromCharCode(x + 65); })
.take(26)
.each(function(char) { console.log(char); });
```

All right... what else?

### Event sequences

With indefinite sequences, we saw that unlike Underscore and Lo-Dash, Lazy.js doesn't actually need an in-memory collection to iterate over. And asynchronous sequences demonstrate that it also doesn't need to do all its iteration at once.
With indefinite sequences, we saw that unlike Underscore and Lodash, Lazy.js doesn't actually need an in-memory collection to iterate over. And asynchronous sequences demonstrate that it also doesn't need to do all its iteration at once.

Now here's a really cool combination of these two features: with a small extension to Lazy.js (lazy.browser.js, a separate file to include in browser-based environments), you can apply all of the power of Lazy.js to **handling DOM events**. In other words, Lazy.js lets you think of DOM events as a *sequence*&mdash;just like any other&mdash;and apply the usual `map`, `filter`, etc. functions on that sequence.

Expand Down
File renamed without changes.
21 changes: 12 additions & 9 deletions lib/lazy.js-0.4.0/Rakefile → lib/lazy.js-0.5.1/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,40 @@ end
def update_json(file_path, updates)
json = JSON.parse(File.read(file_path))
json.merge!(updates)
File.write(file_path, JSON.pretty_generate(json))
File.write(file_path, JSON.pretty_generate(json) + "\n")
end

def format_options(options)
options.map { |key, value| "--#{key} #{value}" }.join(" ")
end

file "lazy.min.js" => [ "lazy.js" ] do |task|
File.open(task.name, 'w') { |f|
desc "Concat and uglify JavaScript"
task :build => [ 'lazy.js', 'lazy.browser.js' ] do |task|
version = package_info['version']

File.open('lazy.min.js', 'w') { |f|
content = task.prerequisites.map { |prereq|
if File.exist?(prereq)
File.read(prereq)
elsif Rake::Task[prereq].nil?
raise "Prerequisite #{prereq} does not exist."
end
}.compact.join("\n")
f.write Uglifier.new.compile(content)

header = "/*! lazy.js #{version} (c)#{Time.now.year} Dan Tao @license MIT */"
minified = Uglifier.new.compile(content)
f.write(header + "\n" + minified + "\n")
}
end

desc "Concat and uglify JavaScript"
task :uglify => [ "lazy.min.js" ]

desc "Update the library version in package.json, bower.json, and component.json"
desc "Update the library version in package.json and component.json"
task :update_version do
if (version = ENV['VERSION']).nil?
puts "Set the VERSION environment variable for this Rake task."
exit
end

update_json('package.json', { 'version' => version })
update_json('bower.json', { 'version' => version })
update_json('component.json', { 'version' => version })
end

Expand All @@ -49,6 +51,7 @@ task :symlinks do
cd site/source/javascripts/lib
ln -s ../../../../lazy.js lazy.js
ln -s ../../../../lazy.browser.js lazy.browser.js
ln -s ../../../../lazy.min.js lazy.min.js
ln -s ../../../../experimental/lazy.json.js lazy.json.js
ln -s ../../../../experimental/lazy.es6.js lazy.es6.js
ln -s ../../../../spec spec
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@
<h1>
{{shortName}}
<small>{{name}}</small>
{{#aliases.length}}
<div class="aliases">
aliases:
{{#aliases}}
<span class="alias">{{.}}</span>
{{/aliases}}
</div>
{{/aliases.length}}
</h1>

{{{description}}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "lazy.js",
"version": "0.4.0",
"main": "lazy.js",
"ignore": [
"**/.*",
Expand All @@ -9,4 +8,4 @@
"site",
"spec"
]
}
}
Loading

0 comments on commit a801aaa

Please sign in to comment.