An open API service indexing awesome lists of open source software.

https://github.com/joyofrails/ruby-enumeration-demo

An interactive visualization of eager and lazy enumeration in Ruby
https://github.com/joyofrails/ruby-enumeration-demo

eager enumeration lazy ruby

Last synced: 8 months ago
JSON representation

An interactive visualization of eager and lazy enumeration in Ruby

Awesome Lists containing this project

README

          

# Ruby Enumeration Demo

A visualization of eager and lazy enumeration in Ruby.

[![Screenshot of demo](./docs/screenshot.jpg 'A screenshot of the demo')](https://joyofrails.github.io/ruby-enumeration-demo/)

https://joyofrails.github.io/ruby-enumeration-demo/

## About

Rubyists love Ruby’s `Enumerable`:

```ruby
1.upto(5).map { |item| item * 2 }.take(3)
# => [2, 4, 6]
```

But Ruby’s `.lazy` enumerator can be confusing:

```ruby
1.upto(5).lazy.map { |item| item * 2 }.take(3).to_a
# => [2, 4, 6]
```

What’s going on here?

This visualization may help illustrate the difference.

## Development

Make sure `node` and `npm` is installed. See `.node-version` for current version.

Install dependencies:

```
npm install
```

Run the Vite dev server:

```
npm run dev
```

Build static assets

```
npm run build
```