<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Achandr9</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Achandr9"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Achandr9"/>
	<updated>2026-05-17T07:00:15Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015&amp;diff=97173</id>
		<title>CSC/ECE 517 Spring 2015</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015&amp;diff=97173"/>
		<updated>2015-10-26T18:57:20Z</updated>

		<summary type="html">&lt;p&gt;Achandr9: /* Writing Assignment 2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Writing Assignment 1==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 17 WL]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 5 ZX]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 6 TZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 4 RW]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 7 SA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 9 RA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 14 RI]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 1 DZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 20 HA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 3 RF]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 12 LS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 13 MA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 2 WA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 21 QW]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 23 MS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 10 GL]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 27 VC]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 22 SF]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 15 SH]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 18 AS]]&lt;br /&gt;
&lt;br /&gt;
==Writing Assignment 2==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1502 wwj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1508 MRS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1504 IMV]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1505 xzl]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1509 lds]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1510 FLP]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1506 SYZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss S1504 AAC]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1507 DG]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss M1502 GVJ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss M1503 EDT]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1503 RSA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1501 YWS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss S1501 OA]]&lt;br /&gt;
&lt;br /&gt;
==Final Project Design Document==&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1526 MPRI]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 S1503 LWJZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 S1524 FSZZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 M1503 EDTS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1529 GLDS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1525 TIAA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1522 Visualization]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1527 SWAR]]&lt;br /&gt;
&lt;br /&gt;
==Final Project Report==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1526]]&lt;/div&gt;</summary>
		<author><name>Achandr9</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_S1501_test&amp;diff=97172</id>
		<title>CSC/ECE 517 Spring 2015/oss S1501 test</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_S1501_test&amp;diff=97172"/>
		<updated>2015-10-26T18:57:02Z</updated>

		<summary type="html">&lt;p&gt;Achandr9: Created page with &amp;quot;test&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;test&lt;/div&gt;</summary>
		<author><name>Achandr9</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015&amp;diff=97171</id>
		<title>CSC/ECE 517 Spring 2015</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015&amp;diff=97171"/>
		<updated>2015-10-26T18:56:54Z</updated>

		<summary type="html">&lt;p&gt;Achandr9: /* Writing Assignment 2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Writing Assignment 1==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 17 WL]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 5 ZX]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 6 TZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 4 RW]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 7 SA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 9 RA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 14 RI]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 1 DZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 20 HA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 3 RF]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 12 LS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 13 MA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 2 WA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 21 QW]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 23 MS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 10 GL]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 27 VC]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 22 SF]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 15 SH]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 18 AS]]&lt;br /&gt;
&lt;br /&gt;
==Writing Assignment 2==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1502 wwj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1508 MRS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1504 IMV]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1505 xzl]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1509 lds]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1510 FLP]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1506 SYZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss S1504 AAC]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1507 DG]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss M1502 GVJ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss M1503 EDT]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1503 RSA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1501 YWS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss S1501 OA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss S1501 test]]&lt;br /&gt;
&lt;br /&gt;
==Final Project Design Document==&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1526 MPRI]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 S1503 LWJZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 S1524 FSZZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 M1503 EDTS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1529 GLDS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1525 TIAA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1522 Visualization]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1527 SWAR]]&lt;br /&gt;
&lt;br /&gt;
==Final Project Report==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1526]]&lt;/div&gt;</summary>
		<author><name>Achandr9</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_M1503_EDTS&amp;diff=96397</id>
		<title>CSC/ECE 517 Spring 2015 M1503 EDTS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_M1503_EDTS&amp;diff=96397"/>
		<updated>2015-04-01T05:37:54Z</updated>

		<summary type="html">&lt;p&gt;Achandr9: /* Sender */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Extending Developer Tools for Servo&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Rust===&lt;br /&gt;
Rust is a general purpose, [http://en.wikipedia.org/wiki/Programming_paradigm#Multi-paradigm multi-paradigm], compiled programming language developed by [http://en.wikipedia.org/wiki/Mozilla Mozilla] Research. It is designed to be a &amp;quot;safe, concurrent, practical language&amp;quot;, supporting [http://en.wikipedia.org/wiki/Purely_functional pure-functional], [http://en.wikipedia.org/wiki/Actor_model concurrent-actor], [http://en.wikipedia.org/wiki/Procedural_programming imperative-procedural], and object-oriented styles.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Rust_%28programming_language%29&amp;lt;/ref&amp;gt; Being a modern systems programming language focusing on safety and speed, it accomplishes these goals by being memory safe without using garbage collection.&amp;lt;ref&amp;gt;http://doc.rust-lang.org/nightly/intro.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
Servo is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. With Servo, we are rethinking the browser at every level of the technology stack — from input parsing to page layout to graphics rendering — to optimize for power efficiency and maximum parallelism.&lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Memory safety at the core of the platform ensures a high degree of assurance in the browser’s trusted computing base. Rust’s lightweight task mechanism also promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation.&amp;lt;ref&amp;gt;https://www.mozilla.org/en-US/research/projects/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Background'''==&lt;br /&gt;
===Remote Developer Tools===&lt;br /&gt;
&lt;br /&gt;
Firefox supports remote developer tools - ie. communicating with an arbitrary server that implements a protocol for exposing information about web content. You can use the [https://developer.mozilla.org/en-US/docs/Tools Firefox developer tools] on your desktop to debug Web sites and Web apps running in other browsers or runtimes. The other browser might be on the same device as the tools themselves or on a different device, such as a phone connected over USB. &lt;br /&gt;
&lt;br /&gt;
Servo implements a very basic developer tools server that currently supports executing JS remotely and investigating the DOM tree in the document inspector. We want to expand these capabilities by completing previous work that enables remote logging from web content, and add new capabilities to log HTTP requests and responses to allow for easier debugging of network-related problems in Servo.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/More-developer-tools-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
=='''Implementation'''==&lt;br /&gt;
=='''Architecture'''==&lt;br /&gt;
&lt;br /&gt;
===enum===&lt;br /&gt;
Enums are datatypes with several alternate representations. A simple enum defines one or more constants with the same data type. In Rust, an enum can have complex variants though, like a struct. For example, consider an enum 'Shape' with variants 'Circle' and 'Triangle' each of which is a struct.&lt;br /&gt;
&lt;br /&gt;
    enum Shape {&lt;br /&gt;
        Circle { center: Point, radius: f64 },&lt;br /&gt;
        Triangle{ vert1: Point, vert2: Point, vert3: Point }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A variable of type Shape can be resolved to its appropriate variant by using a 'match'.&lt;br /&gt;
&lt;br /&gt;
    fn area(sh: Shape) -&amp;gt; f64 {&lt;br /&gt;
        match sh {&lt;br /&gt;
            Circle(_, size) =&amp;gt; f64::consts::PI * size * size,&lt;br /&gt;
            Rectangle(Point { x, y }, Point { x: x2, y: y2 }) =&amp;gt; (x2 - x) * (y2 - y)&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Servo Developers Tools project has a 'DevtoolsControlMsg' enum which is used to instruct the devtools server to update its known actors/state according to changes in the browser. The current project requires the addition of two new variants to the 'DevtoolsControlMsg' enum, namely 'HTTRequest' and 'HTTResponse'.&lt;br /&gt;
&lt;br /&gt;
===Sender&amp;lt;DevtoolsControlMsg&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
In Rust, a pipe is used for communication between tasks. A pipe is simply a pair of endpoints: one for sending messages and another for receiving messages(Sender and Receiver). The simplest way to create a pipe is to use the channel function to create a (Sender, Receiver) pair. In Rust parlance, a sender is a sending endpoint of a pipe, and a receiver is the receiving endpoint. A simple channel can be created as follows:&lt;br /&gt;
    let (tx, rx) = channel();&lt;br /&gt;
    spawn(proc() {&lt;br /&gt;
        tx.send(10i);&lt;br /&gt;
    });&lt;br /&gt;
    assert_eq!(rx.recv(), 10i);&lt;br /&gt;
In this project, whenever a HTTPRequest or a HTTPResponse is received, we are going to send a new message using a 'Sender' object that could send variants of the type 'DevtoolsControlMsg'. This 'Sender&amp;lt;DevtoolsControlMsg&amp;gt;' objects sends the messages at appropriate times in the HTTPLoader function.&lt;br /&gt;
&lt;br /&gt;
===NetworkEventActor===&lt;br /&gt;
&lt;br /&gt;
=='''Design Patterns'''==&lt;br /&gt;
===Actor Model===&lt;br /&gt;
The actor model in computer science is a mathematical model of concurrent computation that treats &amp;quot;actors&amp;quot; as the universal primitives of concurrent computation: in response to a message that it receives, an actor can make local decisions, create more actors, send more messages, and determine how to respond to the next message received.&lt;br /&gt;
&lt;br /&gt;
The Actor model adopts the philosophy that everything is an actor. This is similar to the everything is an object philosophy used by some object-oriented programming languages, but differs in that object-oriented software is typically executed sequentially, while the Actor model is inherently concurrent.&lt;br /&gt;
&lt;br /&gt;
An actor is a computational entity that, in response to a message it receives, can concurrently:&lt;br /&gt;
*send a finite number of messages to other actors;&lt;br /&gt;
*create a finite number of new actors;&lt;br /&gt;
*designate the behavior to be used for the next message it receives.&lt;br /&gt;
&lt;br /&gt;
=='''UML Diagrams'''==&lt;br /&gt;
=='''Proposed Test Cases'''==&lt;br /&gt;
&lt;br /&gt;
=='''Reference'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Achandr9</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_M1503_EDTS&amp;diff=96388</id>
		<title>CSC/ECE 517 Spring 2015 M1503 EDTS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_M1503_EDTS&amp;diff=96388"/>
		<updated>2015-04-01T05:08:41Z</updated>

		<summary type="html">&lt;p&gt;Achandr9: /* Architecture */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Extending Developer Tools for Servo&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Rust===&lt;br /&gt;
Rust is a general purpose, [http://en.wikipedia.org/wiki/Programming_paradigm#Multi-paradigm multi-paradigm], compiled programming language developed by [http://en.wikipedia.org/wiki/Mozilla Mozilla] Research. It is designed to be a &amp;quot;safe, concurrent, practical language&amp;quot;, supporting [http://en.wikipedia.org/wiki/Purely_functional pure-functional], [http://en.wikipedia.org/wiki/Actor_model concurrent-actor], [http://en.wikipedia.org/wiki/Procedural_programming imperative-procedural], and object-oriented styles.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Rust_%28programming_language%29&amp;lt;/ref&amp;gt; Being a modern systems programming language focusing on safety and speed, it accomplishes these goals by being memory safe without using garbage collection.&amp;lt;ref&amp;gt;http://doc.rust-lang.org/nightly/intro.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
Servo is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. With Servo, we are rethinking the browser at every level of the technology stack — from input parsing to page layout to graphics rendering — to optimize for power efficiency and maximum parallelism.&lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Memory safety at the core of the platform ensures a high degree of assurance in the browser’s trusted computing base. Rust’s lightweight task mechanism also promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation.&amp;lt;ref&amp;gt;https://www.mozilla.org/en-US/research/projects/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Background'''==&lt;br /&gt;
===Remote Developer Tools===&lt;br /&gt;
&lt;br /&gt;
Firefox supports remote developer tools - ie. communicating with an arbitrary server that implements a protocol for exposing information about web content. You can use the [https://developer.mozilla.org/en-US/docs/Tools Firefox developer tools] on your desktop to debug Web sites and Web apps running in other browsers or runtimes. The other browser might be on the same device as the tools themselves or on a different device, such as a phone connected over USB. &lt;br /&gt;
&lt;br /&gt;
Servo implements a very basic developer tools server that currently supports executing JS remotely and investigating the DOM tree in the document inspector. We want to expand these capabilities by completing previous work that enables remote logging from web content, and add new capabilities to log HTTP requests and responses to allow for easier debugging of network-related problems in Servo.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/More-developer-tools-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
=='''Implementation'''==&lt;br /&gt;
=='''Architecture'''==&lt;br /&gt;
&lt;br /&gt;
===enum===&lt;br /&gt;
Enums are datatypes with several alternate representations. A simple enum defines one or more constants with the same data type. In Rust, an enum can have complex variants though, like a struct. For example, consider an enum 'Shape' with variants 'Circle' and 'Triangle' each of which is a struct.&lt;br /&gt;
&lt;br /&gt;
    enum Shape {&lt;br /&gt;
        Circle { center: Point, radius: f64 },&lt;br /&gt;
        Triangle{ vert1: Point, vert2: Point, vert3: Point }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
A variable of type Shape can be resolved to its appropriate variant by using a 'match'.&lt;br /&gt;
&lt;br /&gt;
    fn area(sh: Shape) -&amp;gt; f64 {&lt;br /&gt;
        match sh {&lt;br /&gt;
            Circle(_, size) =&amp;gt; f64::consts::PI * size * size,&lt;br /&gt;
            Rectangle(Point { x, y }, Point { x: x2, y: y2 }) =&amp;gt; (x2 - x) * (y2 - y)&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Servo Developers Tools project has a 'DevtoolsControlMsg' enum which is used to instruct the devtools server to update its known actors/state according to changes in the browser. The current project requires the addition of two new variants to the 'DevtoolsControlMsg' enum, namely 'HTTRequest' and 'HTTResponse'.&lt;br /&gt;
&lt;br /&gt;
===Sender&amp;lt;DevtoolsControlMsg&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===NetworkEventActor===&lt;br /&gt;
&lt;br /&gt;
=='''Design Patterns'''==&lt;br /&gt;
===Actor Model===&lt;br /&gt;
The actor model in computer science is a mathematical model of concurrent computation that treats &amp;quot;actors&amp;quot; as the universal primitives of concurrent computation: in response to a message that it receives, an actor can make local decisions, create more actors, send more messages, and determine how to respond to the next message received.&lt;br /&gt;
&lt;br /&gt;
The Actor model adopts the philosophy that everything is an actor. This is similar to the everything is an object philosophy used by some object-oriented programming languages, but differs in that object-oriented software is typically executed sequentially, while the Actor model is inherently concurrent.&lt;br /&gt;
&lt;br /&gt;
An actor is a computational entity that, in response to a message it receives, can concurrently:&lt;br /&gt;
*send a finite number of messages to other actors;&lt;br /&gt;
*create a finite number of new actors;&lt;br /&gt;
*designate the behavior to be used for the next message it receives.&lt;br /&gt;
&lt;br /&gt;
=='''UML Diagrams'''==&lt;br /&gt;
=='''Proposed Test Cases'''==&lt;br /&gt;
&lt;br /&gt;
=='''Reference'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Achandr9</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_S1504_AAC&amp;diff=95156</id>
		<title>CSC/ECE 517 Spring 2015/oss S1504 AAC</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_S1504_AAC&amp;diff=95156"/>
		<updated>2015-03-21T20:53:03Z</updated>

		<summary type="html">&lt;p&gt;Achandr9: /* Searching geonames */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Sahana==&lt;br /&gt;
[http://eden.sahanafoundation.org/ Sahana Eden] is an Open Source Humanitarian Platform which can be used to provide solutions for Disaster Management, Development, and Environmental Management sectors. Being open source, it is easily customisable, extensible and free. It is supported by the [http://sahanafoundation.org/ Sahana Software Foundation]. Sahana Eden was first developed in Sri Lanka as a response to the Indian Ocean Tsunami in 2005. The code for the Sahana Eden project is hosted at [https://github.com/flavour/eden Github] and it is published under the [http://en.wikipedia.org/wiki/MIT_License MIT License]. The demo version of Sahana Eden can be found [http://demo.eden.sahanafoundation.org/eden/ here].&lt;br /&gt;
&lt;br /&gt;
Eden is a flexible humanitarian platform with a rich feature set which can be rapidly customized to adapt to existing processes and integrate with existing systems to provide effective solutions for critical humanitarian needs management either prior to or during a crisis. Sahana Eden contains a number of different modules like 'Organization Registry', 'Project Tracking', 'Human Resources', 'Inventory', 'Assets', 'Assessments', 'Scenarios &amp;amp; Events', 'Mapping', 'Messaging' which can be configured to provide a wide range of functionality.  We are contributing to Sahana Eden as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. In this Wiki Page, we would be explaining the goals of our project and how we implemented them.&lt;br /&gt;
&lt;br /&gt;
==Goals of the project==&lt;br /&gt;
==Implementation==&lt;br /&gt;
===Searching Internal database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    #Get vars from url&lt;br /&gt;
    user_str = get_vars[&amp;quot;name_startsWith&amp;quot;]&lt;br /&gt;
    callback_func = request.vars[&amp;quot;callback&amp;quot;]&lt;br /&gt;
    atable = db.gis_location&lt;br /&gt;
    query = atable.name.lower().like(user_str + '%')&lt;br /&gt;
    rows = db(query).select(atable.id,&lt;br /&gt;
                            atable.level,&lt;br /&gt;
                            atable.name,&lt;br /&gt;
                            atable.lat,&lt;br /&gt;
                           atable.lon&lt;br /&gt;
                            )&lt;br /&gt;
    results = []&lt;br /&gt;
    count = 0&lt;br /&gt;
    for row in rows:&lt;br /&gt;
        count += 1&lt;br /&gt;
        result = {}&lt;br /&gt;
         &lt;br /&gt;
        #Convert the level colum into the ADM codes geonames returns&lt;br /&gt;
        #fcode = row[&amp;quot;gis_location.level&amp;quot;]&lt;br /&gt;
        level = row[&amp;quot;gis_location.level&amp;quot;]&lt;br /&gt;
        if level==&amp;quot;L0&amp;quot;: #Country&lt;br /&gt;
            fcode = &amp;quot;PCL&amp;quot; #Zoom 5&lt;br /&gt;
        elif level==&amp;quot;L1&amp;quot;: #State/Province&lt;br /&gt;
            fcode = &amp;quot;ADM1&amp;quot;&lt;br /&gt;
        elif level==&amp;quot;L2&amp;quot;: #County/District&lt;br /&gt;
            fcode = &amp;quot;ADM2&amp;quot;&lt;br /&gt;
        elif level==&amp;quot;L3&amp;quot;: #Village/Suburb&lt;br /&gt;
            fcode = &amp;quot;ADM3&amp;quot;&lt;br /&gt;
        else: #City/Town/Village&lt;br /&gt;
            fcode = &amp;quot;ADM4&amp;quot;&lt;br /&gt;
             &lt;br /&gt;
        result = {&amp;quot;id&amp;quot; : row[&amp;quot;gis_location.id&amp;quot;],&lt;br /&gt;
                  &amp;quot;fcode&amp;quot; : fcode,&lt;br /&gt;
                  &amp;quot;name&amp;quot; : row[&amp;quot;gis_location.name&amp;quot;],&lt;br /&gt;
                  &amp;quot;lat&amp;quot; : row[&amp;quot;gis_location.lat&amp;quot;],&lt;br /&gt;
                  &amp;quot;lng&amp;quot; : row[&amp;quot;gis_location.lon&amp;quot;]}&lt;br /&gt;
        results.append(result)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Searching geonames===&lt;br /&gt;
&lt;br /&gt;
If the initial search for the user query on the internal 'Locations' table, then a search is done on [http://www.geonames.org/ Geonames] as a fallback. This fallback search is implemented within the 'gis' controller using 'urllib2' an extensible Python module for opening URLs. The base URL for the Geonames search is http://ws.geonames.org/searchJSON?. The searchJSON action expects the Geonames username, the prefix of the location names to be searched, number of rows in the JSON result, etc. as parameters.  The following code performs the HTTP GET request and loads the JSON response in a dictionary.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
username = settings.get_gis_geonames_username()&lt;br /&gt;
maxrows = &amp;quot;20&amp;quot;&lt;br /&gt;
lang = &amp;quot;en&amp;quot;&lt;br /&gt;
charset = &amp;quot;UTF8&amp;quot;&lt;br /&gt;
nameStartsWith = user_str&lt;br /&gt;
geonames_base_url = &amp;quot;http://ws.geonames.org/searchJSON?&amp;quot;&lt;br /&gt;
url = &amp;quot;%susername=%s&amp;amp;maxRows=%s&amp;amp;lang=%s&amp;amp;charset=%s&amp;amp;name_startsWith=%s&amp;quot; % (geonames_base_url,username,maxrows,lang,charset,nameStartsWith)&lt;br /&gt;
response = urllib2.urlopen(url)&lt;br /&gt;
dictResponse = json.loads(response.read().decode(response.info().getparam('charset') or 'utf-8'))&lt;br /&gt;
response.close()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JSON object in the response has two keys 'totalResultsCount' and 'geonames'. The object corresponding to the 'geonames' key is an array of the Geonames search results, each of which is a dictionary in itself. Of all the Keys present in a single result dictionary, the relevant ones are 'id', 'fcode', 'name', 'lat' and 'lng'. The relevant keys are extracted and a new dictionary is created for each search result. The array of new dictionaries is then returned as a response. The following code performs the decoding of the JSON object, creating new dictionary objects with the relevant keys and then collecting them as a single array.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
results = []&lt;br /&gt;
if dictResponse[&amp;quot;totalResultsCount&amp;quot;] != 0:&lt;br /&gt;
    geonamesResults = dictResponse[&amp;quot;geonames&amp;quot;]&lt;br /&gt;
    for geonamesResult in geonamesResults:&lt;br /&gt;
        result = {}&lt;br /&gt;
        result = {&amp;quot;id&amp;quot; : int(geonamesResult[&amp;quot;geonameId&amp;quot;]), &amp;quot;fcode&amp;quot; : str(geonamesResult[&amp;quot;fcode&amp;quot;]),&lt;br /&gt;
                  &amp;quot;name&amp;quot; : str(geonamesResult[&amp;quot;name&amp;quot;]),&amp;quot;lat&amp;quot; : float(geonamesResult[&amp;quot;lat&amp;quot;]),&lt;br /&gt;
                  &amp;quot;lng&amp;quot; : float(geonamesResult[&amp;quot;lng&amp;quot;])}&lt;br /&gt;
        results.append(result)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Achandr9</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_S1504_AAC&amp;diff=95155</id>
		<title>CSC/ECE 517 Spring 2015/oss S1504 AAC</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_S1504_AAC&amp;diff=95155"/>
		<updated>2015-03-21T20:52:39Z</updated>

		<summary type="html">&lt;p&gt;Achandr9: /* Searching geonames */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Sahana==&lt;br /&gt;
[http://eden.sahanafoundation.org/ Sahana Eden] is an Open Source Humanitarian Platform which can be used to provide solutions for Disaster Management, Development, and Environmental Management sectors. Being open source, it is easily customisable, extensible and free. It is supported by the [http://sahanafoundation.org/ Sahana Software Foundation]. Sahana Eden was first developed in Sri Lanka as a response to the Indian Ocean Tsunami in 2005. The code for the Sahana Eden project is hosted at [https://github.com/flavour/eden Github] and it is published under the [http://en.wikipedia.org/wiki/MIT_License MIT License]. The demo version of Sahana Eden can be found [http://demo.eden.sahanafoundation.org/eden/ here].&lt;br /&gt;
&lt;br /&gt;
Eden is a flexible humanitarian platform with a rich feature set which can be rapidly customized to adapt to existing processes and integrate with existing systems to provide effective solutions for critical humanitarian needs management either prior to or during a crisis. Sahana Eden contains a number of different modules like 'Organization Registry', 'Project Tracking', 'Human Resources', 'Inventory', 'Assets', 'Assessments', 'Scenarios &amp;amp; Events', 'Mapping', 'Messaging' which can be configured to provide a wide range of functionality.  We are contributing to Sahana Eden as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. In this Wiki Page, we would be explaining the goals of our project and how we implemented them.&lt;br /&gt;
&lt;br /&gt;
==Goals of the project==&lt;br /&gt;
==Implementation==&lt;br /&gt;
===Searching Internal database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    #Get vars from url&lt;br /&gt;
    user_str = get_vars[&amp;quot;name_startsWith&amp;quot;]&lt;br /&gt;
    callback_func = request.vars[&amp;quot;callback&amp;quot;]&lt;br /&gt;
    atable = db.gis_location&lt;br /&gt;
    query = atable.name.lower().like(user_str + '%')&lt;br /&gt;
    rows = db(query).select(atable.id,&lt;br /&gt;
                            atable.level,&lt;br /&gt;
                            atable.name,&lt;br /&gt;
                            atable.lat,&lt;br /&gt;
                           atable.lon&lt;br /&gt;
                            )&lt;br /&gt;
    results = []&lt;br /&gt;
    count = 0&lt;br /&gt;
    for row in rows:&lt;br /&gt;
        count += 1&lt;br /&gt;
        result = {}&lt;br /&gt;
         &lt;br /&gt;
        #Convert the level colum into the ADM codes geonames returns&lt;br /&gt;
        #fcode = row[&amp;quot;gis_location.level&amp;quot;]&lt;br /&gt;
        level = row[&amp;quot;gis_location.level&amp;quot;]&lt;br /&gt;
        if level==&amp;quot;L0&amp;quot;: #Country&lt;br /&gt;
            fcode = &amp;quot;PCL&amp;quot; #Zoom 5&lt;br /&gt;
        elif level==&amp;quot;L1&amp;quot;: #State/Province&lt;br /&gt;
            fcode = &amp;quot;ADM1&amp;quot;&lt;br /&gt;
        elif level==&amp;quot;L2&amp;quot;: #County/District&lt;br /&gt;
            fcode = &amp;quot;ADM2&amp;quot;&lt;br /&gt;
        elif level==&amp;quot;L3&amp;quot;: #Village/Suburb&lt;br /&gt;
            fcode = &amp;quot;ADM3&amp;quot;&lt;br /&gt;
        else: #City/Town/Village&lt;br /&gt;
            fcode = &amp;quot;ADM4&amp;quot;&lt;br /&gt;
             &lt;br /&gt;
        result = {&amp;quot;id&amp;quot; : row[&amp;quot;gis_location.id&amp;quot;],&lt;br /&gt;
                  &amp;quot;fcode&amp;quot; : fcode,&lt;br /&gt;
                  &amp;quot;name&amp;quot; : row[&amp;quot;gis_location.name&amp;quot;],&lt;br /&gt;
                  &amp;quot;lat&amp;quot; : row[&amp;quot;gis_location.lat&amp;quot;],&lt;br /&gt;
                  &amp;quot;lng&amp;quot; : row[&amp;quot;gis_location.lon&amp;quot;]}&lt;br /&gt;
        results.append(result)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Searching geonames===&lt;br /&gt;
&lt;br /&gt;
If the initial search for the user query on the internal 'Locations' table, then a search is done on [http://www.geonames.org/ Geonames] as a fallback. This fallback search is implemented within the 'gis' controller using 'urllib2' an extensible Python module for opening URLs. The base URL for the Geonames search is http://ws.geonames.org/searchJSON?. The searchJSON action expects the Geonames username, the prefix of the location names to be searched, number of rows in the JSON result, etc. as parameters.  The following code performs the HTTP GET request and loads the JSON response in a dictionary.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
username = settings.get_gis_geonames_username()&lt;br /&gt;
maxrows = &amp;quot;20&amp;quot;&lt;br /&gt;
lang = &amp;quot;en&amp;quot;&lt;br /&gt;
charset = &amp;quot;UTF8&amp;quot;&lt;br /&gt;
nameStartsWith = user_str&lt;br /&gt;
geonames_base_url = &amp;quot;http://ws.geonames.org/searchJSON?&amp;quot;&lt;br /&gt;
url = &amp;quot;%susername=%s&amp;amp;maxRows=%s&amp;amp;lang=%s&amp;amp;charset=%s&amp;amp;name_startsWith=%s&amp;quot; % (geonames_base_url,username,maxrows,lang,charset,nameStartsWith)&lt;br /&gt;
response = urllib2.urlopen(url)&lt;br /&gt;
dictResponse = json.loads(response.read().decode(response.info().getparam('charset') or 'utf-8'))&lt;br /&gt;
response.close()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JSON object in the response has two keys 'totalResultsCount' and 'geonames'. The object corresponding to the 'geonames' key is an array of the Geonames search results, each of which is a dictionary in itself. Of all the Keys present in a single result dictionary, the relevant ones are 'id', 'fcode', 'name', 'lat' and 'lng'. The relevant keys are extracted and a new dictionary is created for each search result. The array of new dictionaries is then returned as a response. The following code performs the decoding of the JSON object, creating new dictionary objects with the relevant keys and then collecting them as a single array.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
results = []&lt;br /&gt;
if dictResponse[&amp;quot;totalResultsCount&amp;quot;] != 0:&lt;br /&gt;
    geonamesResults = dictResponse[&amp;quot;geonames&amp;quot;]&lt;br /&gt;
    for geonamesResult in geonamesResults:&lt;br /&gt;
        result = {}&lt;br /&gt;
        result = {&amp;quot;id&amp;quot; : int(geonamesResult[&amp;quot;geonameId&amp;quot;]), &amp;quot;fcode&amp;quot; : str(geonamesResult[&amp;quot;fcode&amp;quot;]),&lt;br /&gt;
                  &amp;quot;name&amp;quot; : str(geonamesResult[&amp;quot;name&amp;quot;]),&amp;quot;lat&amp;quot; : float(geonamesResult[&amp;quot;lat&amp;quot;]),&lt;br /&gt;
                  &amp;quot;lng&amp;quot; : float(geonamesResult[&amp;quot;lng&amp;quot;])}&lt;br /&gt;
        results.append(result)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Achandr9</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_S1504_AAC&amp;diff=95122</id>
		<title>CSC/ECE 517 Spring 2015/oss S1504 AAC</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_S1504_AAC&amp;diff=95122"/>
		<updated>2015-03-21T20:00:56Z</updated>

		<summary type="html">&lt;p&gt;Achandr9: /* About Sahana */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Sahana==&lt;br /&gt;
[http://eden.sahanafoundation.org/ Sahana Eden] is an Open Source Humanitarian Platform which can be used to provide solutions for Disaster Management, Development, and Environmental Management sectors. Being open source, it is easily customisable, extensible and free. It is supported by the [http://sahanafoundation.org/ Sahana Software Foundation]. Sahana Eden was first developed in Sri Lanka as a response to the Indian Ocean Tsunami in 2005. The code for the Sahana Eden project is hosted at [https://github.com/flavour/eden Github] and it is published under the [http://en.wikipedia.org/wiki/MIT_License MIT License]. The demo version of Sahana Eden can be found [http://demo.eden.sahanafoundation.org/eden/ here].&lt;br /&gt;
&lt;br /&gt;
Eden is a flexible humanitarian platform with a rich feature set which can be rapidly customized to adapt to existing processes and integrate with existing systems to provide effective solutions for critical humanitarian needs management either prior to or during a crisis. Sahana Eden contains a number of different modules like 'Organization Registry', 'Project Tracking', 'Human Resources', 'Inventory', 'Assets', 'Assessments', 'Scenarios &amp;amp; Events', 'Mapping', 'Messaging' which can be configured to provide a wide range of functionality.  We are contributing to Sahana Eden as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. In this Wiki Page, we would be explaining the goals of our project and how we implemented them.&lt;br /&gt;
&lt;br /&gt;
==Goals of the project==&lt;br /&gt;
==Implementation==&lt;br /&gt;
===Searching Internal database===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    #Get vars from url&lt;br /&gt;
    user_str = get_vars[&amp;quot;name_startsWith&amp;quot;]&lt;br /&gt;
    callback_func = request.vars[&amp;quot;callback&amp;quot;]&lt;br /&gt;
    atable = db.gis_location&lt;br /&gt;
    query = atable.name.lower().like(user_str + '%')&lt;br /&gt;
    rows = db(query).select(atable.id,&lt;br /&gt;
                            atable.level,&lt;br /&gt;
                            atable.name,&lt;br /&gt;
                            atable.lat,&lt;br /&gt;
                           atable.lon&lt;br /&gt;
                            )&lt;br /&gt;
    results = []&lt;br /&gt;
    count = 0&lt;br /&gt;
    for row in rows:&lt;br /&gt;
        count += 1&lt;br /&gt;
        result = {}&lt;br /&gt;
         &lt;br /&gt;
        #Convert the level colum into the ADM codes geonames returns&lt;br /&gt;
        #fcode = row[&amp;quot;gis_location.level&amp;quot;]&lt;br /&gt;
        level = row[&amp;quot;gis_location.level&amp;quot;]&lt;br /&gt;
        if level==&amp;quot;L0&amp;quot;: #Country&lt;br /&gt;
            fcode = &amp;quot;PCL&amp;quot; #Zoom 5&lt;br /&gt;
        elif level==&amp;quot;L1&amp;quot;: #State/Province&lt;br /&gt;
            fcode = &amp;quot;ADM1&amp;quot;&lt;br /&gt;
        elif level==&amp;quot;L2&amp;quot;: #County/District&lt;br /&gt;
            fcode = &amp;quot;ADM2&amp;quot;&lt;br /&gt;
        elif level==&amp;quot;L3&amp;quot;: #Village/Suburb&lt;br /&gt;
            fcode = &amp;quot;ADM3&amp;quot;&lt;br /&gt;
        else: #City/Town/Village&lt;br /&gt;
            fcode = &amp;quot;ADM4&amp;quot;&lt;br /&gt;
             &lt;br /&gt;
        result = {&amp;quot;id&amp;quot; : row[&amp;quot;gis_location.id&amp;quot;],&lt;br /&gt;
                  &amp;quot;fcode&amp;quot; : fcode,&lt;br /&gt;
                  &amp;quot;name&amp;quot; : row[&amp;quot;gis_location.name&amp;quot;],&lt;br /&gt;
                  &amp;quot;lat&amp;quot; : row[&amp;quot;gis_location.lat&amp;quot;],&lt;br /&gt;
                  &amp;quot;lng&amp;quot; : row[&amp;quot;gis_location.lon&amp;quot;]}&lt;br /&gt;
        results.append(result)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Searching geonames===&lt;/div&gt;</summary>
		<author><name>Achandr9</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/ch1a_9_RA&amp;diff=93865</id>
		<title>CSC/ECE 517 Spring 2015/ch1a 9 RA</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/ch1a_9_RA&amp;diff=93865"/>
		<updated>2015-02-16T16:48:00Z</updated>

		<summary type="html">&lt;p&gt;Achandr9: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Lazy Enumerators&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29#Ruby_1.8 Ruby 1.8] and [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29#Ruby_1.9 Ruby 1.9] the problem with enumeration that generate infinite sequences is that we have to write special, non-greedy, versions of methods. But, if you’re using [http://en.wikipedia.org/wiki/Ruby_(programming_language)#Ruby_2.0 Ruby 2.0] or later, you have this support built in. When you call lazy a lot happens inside of Ruby to give you just the values you need, Ruby automatically creates and uses many different types of internal Ruby objects. &lt;br /&gt;
&lt;br /&gt;
If you call lazy Enumerator on any Ruby Enumerator, you get back an instance of class [http://www.ruby-doc.org/core-2.0.0/Enumerator/Lazy.html Enumerator::Lazy]. Many basic class like Array and Hash has lazy method through Enumerator class.&amp;lt;ref&amp;gt;http://www.amazon.com/Programming-Ruby-1-9-2-0-Programmers/dp/1937785491&amp;lt;/ref&amp;gt;'lazy' version of some methods such as map and select never returns an array. Instead, they yield the transformed/filtered elements one by one. So you can use them for -&lt;br /&gt;
*Huge data which cannot be processed at a time,&lt;br /&gt;
*Data stream which you want to process in real-time,&lt;br /&gt;
*Infinite list, which has no end.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=='''How a lazy enumerator works'''==&lt;br /&gt;
A lazy enumerator in Ruby works as both a data consumer and a data producer. To understand how it’s done, we have to understand what an Enumerator::Generator and an Enumerator::Yielder is.&lt;br /&gt;
&lt;br /&gt;
A simple way of creating an enumerable series of data in Ruby is to create an array. However if we want more flexibility in handling each element of the series while generating it, we can do so by using an Enumerator::Generator.Consider the example below to create an Enumerator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
even_natural_numbers = Enumerator.new do |yielder|&lt;br /&gt;
	number = 0&lt;br /&gt;
	loop do&lt;br /&gt;
		number += 2&lt;br /&gt;
		yielder.yield number&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here a block with an yielder is passed to the constructor of the enumerator. Every time the next method of the enumerator is called, the block is executed till the point the yielder is called in the line “yielder.yield number”. The control is passed to the yielder and returned back to the enumerator generator block when the “next” method is called on the enumerator again. &lt;br /&gt;
&lt;br /&gt;
[[File:Enumerator-constructor.png‎]]&lt;br /&gt;
&lt;br /&gt;
To understand how the block is executed on each call of “next”, the above code can be modified as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
even_natural_numbers = Enumerator.new do |yielder|&lt;br /&gt;
 number = 0&lt;br /&gt;
 loop do&lt;br /&gt;
   number += 2&lt;br /&gt;
   yielder.yield number&lt;br /&gt;
   puts &amp;quot;continuing loop&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
puts even_natural_numbers.next&lt;br /&gt;
puts even_natural_numbers.next&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
2&lt;br /&gt;
continuing loop&lt;br /&gt;
4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On the first “next” call to ‘even_natural_numbers’, the value of number is 2 and it’s passed to the yielder. During the second “next” call, the execution of the generator block continues from the line ‘puts “continuing loop”’ and the blocks yields again with the value 4.&lt;br /&gt;
&lt;br /&gt;
Printing the above even_natural_numbers object gives the output:&lt;br /&gt;
 #&amp;lt;Enumerator: #&amp;lt;Enumerator::Generator:0x007fbb040b2e28&amp;gt;:each&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows that the enumerator object is created with a reference to an internal object called Enumerator::Generator and the “each” method is setup to call that generator.&lt;br /&gt;
&lt;br /&gt;
In the above example, the enumerator acts as a lazy generator i.e. generating new numbers of the series only on demand. By cascading multiple such lazy enumerators, each enumerator can be made to act as a data generator as well as a consumer. Consider an example where the first 10 even numbers which are also multiples of 5 are to be generated:&lt;br /&gt;
&lt;br /&gt;
If the “select” method is used on the enumerator “even_natural_numbers” as follows, an infinite loop is produced:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
puts even_natural_numbers.select {|v| v%5==0}.first(10)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The reason behind the infinite loop is that the “select” method tries to iterate over the entire collection and doesn't pass the control to the next method in line unless the collection is exhausted which, in an infinite collection, never happens. Hence it’s necessary to define a lazy version of the select method to do something useful with the infinite range that’s being lazily generated.&amp;lt;ref&amp;gt;http://www.michaelharrison.ws/weblog/?p=163&amp;lt;/ref&amp;gt; The code given below adds a lazy version of the “select” method to the existing “Enumerator” class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Enumerator&lt;br /&gt;
 def lazy_select(&amp;amp;block)&lt;br /&gt;
   Enumerator.new do |yielder|&lt;br /&gt;
     self.each do |val|&lt;br /&gt;
       yielder.yield(val) if block.call(val)&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The lazy_select method creates an enumerator which yields to the next method in line on selecting each value that satisfies the condition in the block. Using the lazy_select method on even_natural_numbers won't give an infinite loop anymore. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
puts even_natural_numbers.lazy_select {|v| v%5==0}.first(5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above line of code gives the output as:&lt;br /&gt;
10&lt;br /&gt;
20&lt;br /&gt;
30&lt;br /&gt;
40&lt;br /&gt;
50&lt;br /&gt;
&lt;br /&gt;
The flow of numbers in the above chain of lazy methods can be illustrated as below:&lt;br /&gt;
[[File:Lazy-select.png‎]]&lt;br /&gt;
&lt;br /&gt;
=='''Differences '''==&lt;br /&gt;
If you try to iterate over an infinite range in Enumerator then it will run  into an endless loop while with Enumerator::Lazy you can avoid endless loop and get just the value you need.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; range = 1..Float::INFINITY&lt;br /&gt;
&amp;gt; range.collect { |n| n**2}.first(10) #endless loop  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
but with lazy,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; range = 1..Float::INFINITY&lt;br /&gt;
&amp;gt; range.lazy.collect { |n| n**2}.first(10)&lt;br /&gt;
=&amp;gt; [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enumerator::Lazy acts just like the original, but it re-implements methods such as select and map so that they can work with infinite sequences. The lazy versions of the various methods do not return arrays of data. Instead, it returns a new enumerator that includes its own special processing—below example of map method returns an enumerator.&amp;lt;ref&amp;gt;http://patshaughnessy.net/2013/4/3/ruby-2-0-works-hard-so-you-can-be-lazy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; range = 1..100&lt;br /&gt;
&amp;gt; range.map{|n| n**2}.take(10) #returns array&lt;br /&gt;
=&amp;gt; [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Enumerator map.png ]]&lt;br /&gt;
&lt;br /&gt;
but with lazy,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; range.lazy.map{|n| n**2}.take(10) #returns enumerator&lt;br /&gt;
=&amp;gt;#&amp;lt;Enumerator::Lazy:#&amp;lt;Enumerator::Lazy:#&amp;lt;Enumerator::Lazy:1..100&amp;gt;:map&amp;gt;:take(10)&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Examples '''==&lt;br /&gt;
&lt;br /&gt;
===Example 1===&lt;br /&gt;
Enumerator::lazy manipulate infinite lists wisely. Below example shows without '.lazy', map tries to evaluate an array till last value and then gives first 10 values So, it takes much longer time to evaluate. But, with '.Lazy' method instead of evaluating full length array it evaluates only first 10 values. Thus, it gives answer much quicker than without '.Lazy' method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'date'&lt;br /&gt;
require ‘benchmark’&lt;br /&gt;
Benchmark.bm(8) do |x|&lt;br /&gt;
	x.report(&amp;quot;Non Lazy :&amp;quot;) do&lt;br /&gt;
		puts (Date.new(2015)..Date.new(9999)).select{|d| d.day == 13 and d.friday?}.first(10)&lt;br /&gt;
	end&lt;br /&gt;
	x.report(&amp;quot;Lazy :&amp;quot;) do&lt;br /&gt;
		puts (Date.new(2015)..Date.new(9999)).lazy.select{|d| d.day == 13 and d.friday?}.first(10)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example 2===&lt;br /&gt;
&lt;br /&gt;
This example give you idea of using lazy enumeration in file read example and comparing with non lazy enumeration way,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'benchmark'&lt;br /&gt;
fileName = &amp;quot;C:\\sample.txt&amp;quot;&lt;br /&gt;
Benchmark.bm(8) do |x|&lt;br /&gt;
		x.report(&amp;quot;Non Lazy :&amp;quot;) do&lt;br /&gt;
		50.times { File.readlines(fileName).detect { |line| line =~ /110216/i} }&lt;br /&gt;
		end&lt;br /&gt;
	x.report(&amp;quot;Lazy :&amp;quot;) do&lt;br /&gt;
			50.times { File.open(fileName).lazy.detect { |line| line =~ /110216/i} }&lt;br /&gt;
		end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you deal with large data and start chaining multiple enumeration methods together, the use of lazy evaluation prevents you from using unnecessary amounts of memory in temporary variables which makes lazy evaluation faster than non lazy evaluation.&lt;br /&gt;
&lt;br /&gt;
=='''Drawbacks'''==&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
We have seen usage and benefits of lazy enumeration in above examples but below simple example will give you drawback of it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'benchmark'&lt;br /&gt;
Benchmark.bm(8) do |x|&lt;br /&gt;
	x.report(&amp;quot;Non Lazy :&amp;quot;) do&lt;br /&gt;
		(1..10000000).select { |i| i % 3 == 0 || i % 5 == 0}.reduce(:+)&lt;br /&gt;
	end&lt;br /&gt;
	x.report(&amp;quot;Lazy :&amp;quot;) do&lt;br /&gt;
		(1..10000000).lazy.select { |i| i % 3 == 0 || i % 5 == 0}.reduce(:+)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lazy enumeration is act as a proxy in between program and data so sometimes lazy enumeration gives non negligible performance hit. It is recommended not to use lazy enumeration everywhere as it adds another layer.&amp;lt;ref&amp;gt;https://bugs.ruby-lang.org/issues/6183&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''[http://www.ruby-doc.org/core-2.0.0/Enumerator/Lazy.html Methods]'''==&lt;br /&gt;
Enumerator::Lazy overrides the following methods as 'lazy' version.&lt;br /&gt;
# Methods which transform the element: &lt;br /&gt;
##map(collect), &lt;br /&gt;
##flat_map(collect_concat), &lt;br /&gt;
##zip &lt;br /&gt;
# Methods which filters the element:&lt;br /&gt;
##select(find_all)&lt;br /&gt;
##grep&lt;br /&gt;
##take_while&lt;br /&gt;
##reject&lt;br /&gt;
##drop&lt;br /&gt;
##drop_while&lt;br /&gt;
# These lazy methods returns an instance of Enumerator::Lazy, where the 'normal' version returns an Array (and goes into infinite loop). It means that calling these methods does not generate any result. Actual values are generated when you call the methods like these on Enumerable::Lazy.&lt;br /&gt;
##take&lt;br /&gt;
##first&lt;br /&gt;
##find(detect)&lt;br /&gt;
#Enumerator::Lazy does not override these methods:&lt;br /&gt;
##chunk, cycle, slicebefore, each_cons, each_entry, each_slice,each_with_index, each_with_object.&lt;br /&gt;
##:Because they return an Enumerator. &lt;br /&gt;
##any?, include?, take. detect, find_index, first.&lt;br /&gt;
##:Because they never cause an infinite loop, because they need only finite number of elements&lt;br /&gt;
##inject, count, all?, none?, one?, max, max_by, min, min_by, minmax, minmax_by.&lt;br /&gt;
##:Because they need all elements to define the return value, and they are smart enough not to store all the element on the memory.&lt;br /&gt;
##entries, group_by, partition, sort, sort_by&lt;br /&gt;
##:Because of the size of their return value is linear to the input size.&lt;br /&gt;
##reverse_each&lt;br /&gt;
##:Because it needs the last element first.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Achandr9</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/ch1a_9_RA&amp;diff=93620</id>
		<title>CSC/ECE 517 Spring 2015/ch1a 9 RA</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/ch1a_9_RA&amp;diff=93620"/>
		<updated>2015-02-10T00:17:18Z</updated>

		<summary type="html">&lt;p&gt;Achandr9: /* How a lazy enumerator works */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Lazy Enumerators&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29#Ruby_1.8 Ruby 1.8] and [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29#Ruby_1.9 Ruby 1.9] the problem with enumeration that generate infinite sequences is that we have to write special, non-greedy, versions of methods. But, if you’re using [http://en.wikipedia.org/wiki/Ruby_(programming_language)#Ruby_2.0 Ruby 2.0] or later, you have this support built in. If you call Enumerator#lazy on any Ruby enumerator, you get back an instance of class [http://www.ruby-doc.org/core-2.0.0/Enumerator/Lazy.html Enumerator::Lazy]. Many basic class like Array and Hash has lazy method through Enumerator class.&amp;lt;ref&amp;gt;Programming Ruby 1.9 &amp;amp; 2.0 4th Edition&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=='''[http://www.ruby-doc.org/core-2.0.0/Enumerator/Lazy.html Methods]'''==&lt;br /&gt;
Enumerable::Lazy overrides the following methods as 'lazy' version.&lt;br /&gt;
# Methods which transform the element: &lt;br /&gt;
##map(collect), &lt;br /&gt;
##flat_map(collect_concat), &lt;br /&gt;
##zip &lt;br /&gt;
# Methods which filters the element:&lt;br /&gt;
##select(find_all)&lt;br /&gt;
##grep&lt;br /&gt;
##take_while&lt;br /&gt;
##reject&lt;br /&gt;
##drop&lt;br /&gt;
##drop_while&lt;br /&gt;
# These lazy methods returns an instance of Enumerable::Lazy, where the 'normal' version returns an Array (and goes into infinite loop). It means that calling these methods does not generate any result. Actual values are generated when you call the methods like these on Enumerable::Lazy.&lt;br /&gt;
##take&lt;br /&gt;
##first&lt;br /&gt;
##find(detect)&lt;br /&gt;
#Enumerable::Lazy does not override these methods:&lt;br /&gt;
##chunk, cycle, slicebefore, each_cons, each_entry, each_slice,each_with_index, each_with_object.&lt;br /&gt;
##:Because they return an Enumerator. &lt;br /&gt;
##any?, include?, take. detect, find_index, first.&lt;br /&gt;
##:Because they never cause an infinite loop, because they need only finite number of elements&lt;br /&gt;
##inject, count, all?, none?, one?, max, max_by, min, min_by, minmax, minmax_by.&lt;br /&gt;
##:Because they need all elements to define the return value, and they are smart enough not to store all the element on the memory.&lt;br /&gt;
##entries, group_by, partition, sort, sort_by&lt;br /&gt;
##:Because of the size of their return value is linear to the input size.&lt;br /&gt;
##reverse_each&lt;br /&gt;
##:Because it needs the last element first.&lt;br /&gt;
&lt;br /&gt;
=='''How a lazy enumerator works'''==&lt;br /&gt;
A lazy enumerator in Ruby works as both a data consumer and a data producer. To understand how it’s done, we have to understand what an Enumerator::Generator and an Enumerator::Yielder is.&lt;br /&gt;
&lt;br /&gt;
A simple way of creating an enumerable series of data in Ruby is to create an array. However if we want more flexibility in handling each element of the series while generating it, we can do so by using an Enumerator::Generator.Consider the example below to create an Enumerator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
even_natural_numbers = Enumerator.new do |yielder|&lt;br /&gt;
	number = 0&lt;br /&gt;
	loop do&lt;br /&gt;
		number += 2&lt;br /&gt;
		yielder.yield number&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here a block with an yielder is passed to the constructor of the enumerator. Every time the next method of the enumerator is called, the block is executed till the point the yielder is called in the line “yielder.yield number”. The control is passed to the yielder and returned back to the enumerator generator block when the “next” method is called on the enumerator again. &lt;br /&gt;
&lt;br /&gt;
[[File:Enumerator-constructor.png‎]]&lt;br /&gt;
&lt;br /&gt;
To understand how the block is executed on each call of “next”, the above code can be modified as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
even_natural_numbers = Enumerator.new do |yielder|&lt;br /&gt;
 number = 0&lt;br /&gt;
 loop do&lt;br /&gt;
   number += 2&lt;br /&gt;
   yielder.yield number&lt;br /&gt;
   puts &amp;quot;continuing loop&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
puts even_natural_numbers.next&lt;br /&gt;
puts even_natural_numbers.next&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
2&lt;br /&gt;
continuing loop&lt;br /&gt;
4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On the first “next” call to ‘even_natural_numbers’, the value of number is 2 and it’s passed to the yielder. During the second “next” call, the execution of the generator block continues from the line ‘puts “continuing loop”’ and the blocks yields again with the value 4.&lt;br /&gt;
&lt;br /&gt;
Printing the above even_natural_numbers object gives the output:&lt;br /&gt;
 #&amp;lt;Enumerator: #&amp;lt;Enumerator::Generator:0x007fbb040b2e28&amp;gt;:each&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows that the enumerator object is created with a reference to an internal object called Enumerator::Generator and the “each” method is setup to call that generator.&lt;br /&gt;
&lt;br /&gt;
In the above example, the enumerator acts as a lazy generator i.e. generating new numbers of the series only on demand. By cascading multiple such lazy enumerators, each enumerator can be made to act as a data generator as well as a consumer. Consider an example where the first 10 even numbers which are also multiples of 5 are to be generated:&lt;br /&gt;
&lt;br /&gt;
If the “select” method is used on the enumerator “even_natural_numbers” as follows, an infinite loop is produced:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
puts even_natural_numbers.select {|v| v%5==0}.first(10)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The reason behind the infinite loop is that the “select” method tries to iterate over the entire collection and doesn't pass the control to the next method in line unless the collection is exhausted which, in an infinite collection, never happens. Hence it’s necessary to define a lazy version of the select method to do something useful with the infinite range that’s being lazily generated.&amp;lt;ref&amp;gt;http://www.michaelharrison.ws/weblog/?p=163&amp;lt;/ref&amp;gt; The code given below adds a lazy version of the “select” method to the existing “Enumerator” class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Enumerator&lt;br /&gt;
 def lazy_select(&amp;amp;block)&lt;br /&gt;
   Enumerator.new do |yielder|&lt;br /&gt;
     self.each do |val|&lt;br /&gt;
       yielder.yield(val) if block.call(val)&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The lazy_select method creates an enumerator which yields to the next method in line on selecting each value that satisfies the condition in the block. Using the lazy_select method on even_natural_numbers won't give an infinite loop anymore. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
puts even_natural_numbers.lazy_select {|v| v%5==0}.first(5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above line of code gives the output as:&lt;br /&gt;
10&lt;br /&gt;
20&lt;br /&gt;
30&lt;br /&gt;
40&lt;br /&gt;
50&lt;br /&gt;
&lt;br /&gt;
The flow of numbers in the above chain of lazy methods can be illustrated as below:&lt;br /&gt;
[[File:Lazy-select.png‎]]&lt;br /&gt;
&lt;br /&gt;
=='''Differences '''==&lt;br /&gt;
If you try to iterate over an infinite range in Enumerator then it will run  into an endless loop while with Enumerator::Lazy you can avoid endless loop and get just the value you need.&amp;lt;ref&amp;gt;http://patshaughnessy.net/2013/4/3/ruby-2-0-works-hard-so-you-can-be-lazy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; range = 1..Float::INFINITY&lt;br /&gt;
&amp;gt; range.collect { |n| n**2}.first(10) #endless loop  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
but with lazy,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; range = 1..Float::INFINITY&lt;br /&gt;
&amp;gt; range.lazy.collect { |n| n**2}.first(10)&lt;br /&gt;
=&amp;gt; [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enumerator::Lazy acts just like the original, but it re-implements methods such as select and map so that they can work with infinite sequences. The lazy versions of the various methods do not return arrays of data. Instead, it returns a new enumerator that includes its own special processing—below example of map method returns an enumerator.&amp;lt;ref&amp;gt;http://patshaughnessy.net/2013/4/3/ruby-2-0-works-hard-so-you-can-be-lazy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; range = 1..100&lt;br /&gt;
&amp;gt; range.map{|n| n**2}.take(10) #returns array&lt;br /&gt;
=&amp;gt; [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Enumerator map.png ]]&lt;br /&gt;
&lt;br /&gt;
but with lazy,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; range.lazy.map{|n| n**2}.take(10) #returns enumerator&lt;br /&gt;
=&amp;gt;#&amp;lt;Enumerator::Lazy:#&amp;lt;Enumerator::Lazy:#&amp;lt;Enumerator::Lazy:1..100&amp;gt;:map&amp;gt;:take(10)&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Examples '''==&lt;br /&gt;
&lt;br /&gt;
===Example 1===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'date'&lt;br /&gt;
require ‘benchmark’&lt;br /&gt;
Benchmark.bm(8) do |x|&lt;br /&gt;
	x.report(&amp;quot;Non Lazy :&amp;quot;) do&lt;br /&gt;
		puts (Date.new(2015)..Date.new(9999)).select{|d| d.day == 13 and d.friday?}.first(10)&lt;br /&gt;
	end&lt;br /&gt;
	x.report(&amp;quot;Lazy :&amp;quot;) do&lt;br /&gt;
		puts (Date.new(2015)..Date.new(9999)).lazy.select{|d| d.day == 13 and d.friday?}.first(10)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example 2===&lt;br /&gt;
&lt;br /&gt;
This example give you idea of using lazy enumeration in file read example and comparing with non lazy enumeration way&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'benchmark'&lt;br /&gt;
fileName = &amp;quot;C:\\sample.txt&amp;quot;&lt;br /&gt;
Benchmark.bm(8) do |x|&lt;br /&gt;
		x.report(&amp;quot;Non Lazy :&amp;quot;) do&lt;br /&gt;
		50.times { File.readlines(fileName).detect { |line| line =~ /110216/i} }&lt;br /&gt;
		end&lt;br /&gt;
	x.report(&amp;quot;Lazy :&amp;quot;) do&lt;br /&gt;
			50.times { File.open(fileName).lazy.detect { |line| line =~ /110216/i} }&lt;br /&gt;
		end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you deal with large data and start chaining multiple enumeration methods together, the use of lazy evaluation prevents you from using unnecessary amounts of memory in temporary variables which makes lazy evaluation faster than non lazy evaluation. &lt;br /&gt;
&lt;br /&gt;
=='''Drawbacks'''==&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
We have seen usage and benefits of lazy enumeration in above examples but below simple example will give you drawback of it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'benchmark'&lt;br /&gt;
Benchmark.bm(8) do |x|&lt;br /&gt;
	x.report(&amp;quot;Non Lazy :&amp;quot;) do&lt;br /&gt;
		(1..10000000).select { |i| i % 3 == 0 || i % 5 == 0}.reduce(:+)&lt;br /&gt;
	end&lt;br /&gt;
	x.report(&amp;quot;Lazy :&amp;quot;) do&lt;br /&gt;
		(1..10000000).lazy.select { |i| i % 3 == 0 || i % 5 == 0}.reduce(:+)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lazy enumeration is act as a proxy in between program and data so sometimes lazy enumeration gives non negligible performance hit. It is recommended not to use lazy enumeration everywhere as it adds another layer.&amp;lt;ref&amp;gt;https://bugs.ruby-lang.org/issues/6183&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Achandr9</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Enumerator-constructor.png&amp;diff=93619</id>
		<title>File:Enumerator-constructor.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Enumerator-constructor.png&amp;diff=93619"/>
		<updated>2015-02-10T00:16:28Z</updated>

		<summary type="html">&lt;p&gt;Achandr9: uploaded a new version of &amp;amp;quot;File:Enumerator-constructor.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Achandr9</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Enumerator-constructor.png&amp;diff=93618</id>
		<title>File:Enumerator-constructor.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Enumerator-constructor.png&amp;diff=93618"/>
		<updated>2015-02-10T00:15:53Z</updated>

		<summary type="html">&lt;p&gt;Achandr9: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Achandr9</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Enumerator-generator.png&amp;diff=93602</id>
		<title>File:Enumerator-generator.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Enumerator-generator.png&amp;diff=93602"/>
		<updated>2015-02-09T22:41:13Z</updated>

		<summary type="html">&lt;p&gt;Achandr9: uploaded a new version of &amp;amp;quot;File:Enumerator-generator.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Achandr9</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/ch1a_9_RA&amp;diff=93545</id>
		<title>CSC/ECE 517 Spring 2015/ch1a 9 RA</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/ch1a_9_RA&amp;diff=93545"/>
		<updated>2015-02-09T19:16:20Z</updated>

		<summary type="html">&lt;p&gt;Achandr9: /* Differences  */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Lazy Enumerators&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
In Ruby 1.8 and Ruby 1.9 the problem with enumeration that generate infinite sequences is that we have to write special, non-greedy, versions of methods. But, if you’re using Ruby 2.0 or later, you have this support built in. If you call Enumerator#lazy on any Ruby enumerator, you get back an instance of class Enumerator::Lazy. Many basic class like Array and Hash has lazy method through Enumerator class.&amp;lt;ref&amp;gt;Programming Ruby 1.9 &amp;amp; 2.0 4th Edition&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The lazy methods returns a lazy enumerator whose methods Map/collect, flat_map/ collect_caoncat, select/ find_all, reject, grep, zip, take, #take_while, drop, #drop_while, and cycle enumerate values only on as-needed basis.&amp;lt;ref&amp;gt;http://www.ruby-doc.org/core-2.0.0/Enumerator/Lazy.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
=='''How a lazy enumerator works'''==&lt;br /&gt;
A lazy enumerator in Ruby works as both a data consumer and a data producer. To understand how it’s done, we have to understand what an Enumerator::Generator and an Enumerator::Yielder is.&lt;br /&gt;
&lt;br /&gt;
A simple way of creating an enumerable series of data in Ruby is to create an array. However if we want more flexibility in handling each element of the series while generating it, we can do so by using an Enumerator::Generator.&amp;lt;ref&amp;gt;33333333333333&amp;lt;/ref&amp;gt; Consider the example below to create an Enumerator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
even_natural_numbers = Enumerator.new do |yielder|&lt;br /&gt;
	number = 0&lt;br /&gt;
	loop do&lt;br /&gt;
		number += 2&lt;br /&gt;
		yielder.yield number&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here a block with an yielder is passed to the constructor of the enumerator. Everytime the next method of the enumerator is called, the block is executed till the point the yielder is called in the line “yielder.yield number”. The control is passed to the yielder and returned back to the enumerator generator block when the “next” method is called on the enumerator again. &lt;br /&gt;
&lt;br /&gt;
[[File:Enumerator-generator.png‎]]&lt;br /&gt;
&lt;br /&gt;
To understand how the block is executed on each call of “next”, the above code can be modified as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
even_natural_numbers = Enumerator.new do |yielder|&lt;br /&gt;
 number = 0&lt;br /&gt;
 loop do&lt;br /&gt;
   number += 2&lt;br /&gt;
   yielder.yield number&lt;br /&gt;
   puts &amp;quot;continuing loop&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
puts even_natural_numbers.next&lt;br /&gt;
puts even_natural_numbers.next&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
2&lt;br /&gt;
continuing loop&lt;br /&gt;
4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On the first “next” call to ‘even_natural_numbers’, the value of number is 2 and it’s passed to the yielder. During the second “next” call, the execution of the generator block continues from the line ‘puts “continuing loop”’ and the blocks yields again with the value 4.&lt;br /&gt;
&lt;br /&gt;
Printing the above even_natural_numbers object gives the output:&lt;br /&gt;
 #&amp;lt;Enumerator: #&amp;lt;Enumerator::Generator:0x007fbb040b2e28&amp;gt;:each&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows that the enumerator object is created with a reference to an internal object called Enumerator::Generator and the “each” method is setup to call that generator.&lt;br /&gt;
&lt;br /&gt;
In the above example, the enumerator acts as a lazy generator i.e. generating new numbers of the series only on demand. By cascading multiple such lazy enumerators, each enumerator can be made to act as a data generator as well as a consumer. Consider an example where the first 10 even numbers which are also multiples of 5 are to be generated:&lt;br /&gt;
&lt;br /&gt;
If the “select” method is used on the enumerator “even_natural_numbers” as follows, an infinite loop is produced:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
puts even_natural_numbers.select {|v| v%5==0}.first(10)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The reason behind the infinite loop is that the “select” method tries to iterate over the entire collection and doesn’t pass the control to the next method in line unless the collection is exhausted which, in an infinite collection, never happens. Hence it’s necessary to define a lazy version of the select method to do something useful with the infinite range that’s being lazily generated. The code given below adds a lazy version of the “select” method to the existing “Enumerator” class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Enumerator&lt;br /&gt;
 def lazy_select(&amp;amp;block)&lt;br /&gt;
   Enumerator.new do |yielder|&lt;br /&gt;
     self.each do |val|&lt;br /&gt;
       yielder.yield(val) if block.call(val)&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The lazy_select method creates an enumerator which yields to the next method in line on selecting each value that satisfies the condition in the block. Using the lazy_select method on even_natural_numbers won't give an infinte loop anymore. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
puts even_natural_numbers.lazy_select {|v| v%5==0}.first(5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above line of code gives the output as:&lt;br /&gt;
10&lt;br /&gt;
20&lt;br /&gt;
30&lt;br /&gt;
40&lt;br /&gt;
50&lt;br /&gt;
&lt;br /&gt;
The flow of numbers in the above chain of lazy methods can be illustrated as below:&lt;br /&gt;
[[File:Lazy-select.png‎]]&lt;br /&gt;
&lt;br /&gt;
=='''Differences '''==&lt;br /&gt;
If you try to iterate over an infinite range in Enumerator then it will run  into an endless loop while with Enumerator::Lazy you can avoid endless loop and get just the value you need.&amp;lt;ref&amp;gt;http://patshaughnessy.net/2013/4/3/ruby-2-0-works-hard-so-you-can-be-lazy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; range = 1..Float::INFINITY&lt;br /&gt;
&amp;gt; range.collect { |n| n**2}.first(10) #endless loop  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
but with lazy,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; range = 1..Float::INFINITY&lt;br /&gt;
&amp;gt; range.lazy.collect { |n| n**2}.first(10)&lt;br /&gt;
=&amp;gt; [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enumerator::Lazy acts just like the original, but it re-implements methods such as select and map so that they can work with infinite sequences. The lazy versions of the various methods do not return arrays of data. Instead, it returns a new enumerator that includes its own special processing—below example of map method returns an enumerator.&amp;lt;ref&amp;gt;http://patshaughnessy.net/2013/4/3/ruby-2-0-works-hard-so-you-can-be-lazy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; range = 1..100&lt;br /&gt;
&amp;gt; range.map{|n| n**2}.take(10) #returns array&lt;br /&gt;
=&amp;gt; [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Enumerator map.png ]]&lt;br /&gt;
&lt;br /&gt;
but with lazy,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; range.lazy.map{|n| n**2}.take(10) #returns enumerator&lt;br /&gt;
=&amp;gt;#&amp;lt;Enumerator::Lazy:#&amp;lt;Enumerator::Lazy:#&amp;lt;Enumerator::Lazy:1..100&amp;gt;:map&amp;gt;:take(10)&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Examples '''==&lt;br /&gt;
&lt;br /&gt;
===Example 1===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'date'&lt;br /&gt;
require ‘benchmark’&lt;br /&gt;
Benchmark.bm(8) do |x|&lt;br /&gt;
	x.report(&amp;quot;Non Lazy :&amp;quot;) do&lt;br /&gt;
		puts (Date.new(2015)..Date.new(9999)).select{|d| d.day == 13 and d.friday?}.first(10)&lt;br /&gt;
	end&lt;br /&gt;
	x.report(&amp;quot;Lazy :&amp;quot;) do&lt;br /&gt;
		puts (Date.new(2015)..Date.new(9999)).lazy.select{|d| d.day == 13 and d.friday?}.first(10)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example 2===&lt;br /&gt;
&lt;br /&gt;
This example give you idea of using lazy enumeration in file read example and comparing with non lazy enumeration way&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'benchmark'&lt;br /&gt;
fileName = &amp;quot;C:\\sample.txt&amp;quot;&lt;br /&gt;
Benchmark.bm(8) do |x|&lt;br /&gt;
		x.report(&amp;quot;Non Lazy :&amp;quot;) do&lt;br /&gt;
		50.times { File.readlines(fileName).detect { |line| line =~ /110216/i} }&lt;br /&gt;
		end&lt;br /&gt;
	x.report(&amp;quot;Lazy :&amp;quot;) do&lt;br /&gt;
			50.times { File.open(fileName).lazy.detect { |line| line =~ /110216/i} }&lt;br /&gt;
		end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you deal with large data and start chaining multiple enumeration methods together, the use of lazy evaluation prevents you from using unnecessary amounts of memory in temporary variables which makes lazy evaluation faster than non lazy evaluation. &lt;br /&gt;
&lt;br /&gt;
=='''Drawbacks'''==&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
We have seen usage and benefits of lazy enumeration in above examples but below simple example will give you drawback of it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'benchmark'&lt;br /&gt;
Benchmark.bm(8) do |x|&lt;br /&gt;
	x.report(&amp;quot;Non Lazy :&amp;quot;) do&lt;br /&gt;
		(1..10000000).select { |i| i % 3 == 0 || i % 5 == 0}.reduce(:+)&lt;br /&gt;
	end&lt;br /&gt;
	x.report(&amp;quot;Lazy :&amp;quot;) do&lt;br /&gt;
		(1..10000000).lazy.select { |i| i % 3 == 0 || i % 5 == 0}.reduce(:+)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lazy enumeration is act as a proxy in between program and data so sometimes lazy enumeration gives non negligible performance hit. It is recommended not to use lazy enumeration everywhere as it adds another layer.&amp;lt;ref&amp;gt;https://bugs.ruby-lang.org/issues/6183&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Achandr9</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Enumerator_map.png&amp;diff=93544</id>
		<title>File:Enumerator map.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Enumerator_map.png&amp;diff=93544"/>
		<updated>2015-02-09T19:10:36Z</updated>

		<summary type="html">&lt;p&gt;Achandr9: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Achandr9</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/ch1a_9_RA&amp;diff=93540</id>
		<title>CSC/ECE 517 Spring 2015/ch1a 9 RA</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/ch1a_9_RA&amp;diff=93540"/>
		<updated>2015-02-09T17:33:05Z</updated>

		<summary type="html">&lt;p&gt;Achandr9: /* How a lazy enumerator works */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Lazy Enumerators&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
In Ruby 1.8 and Ruby 1.9 the problem with enumeration that generate infinite sequences is that we have to write special, non-greedy, versions of methods. But, if you’re using Ruby 2.0 or later, you have this support built in. If you call Enumerator#lazy on any Ruby enumerator, you get back an instance of class Enumerator::Lazy. Many basic class like Array and Hash has lazy method through Enumerator class.&amp;lt;ref&amp;gt;Programming Ruby 1.9 &amp;amp; 2.0 4th Edition&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The lazy methods returns a lazy enumerator whose methods Map/collect, flat_map/ collect_caoncat, select/ find_all, reject, grep, zip, take, #take_while, drop, #drop_while, and cycle enumerate values only on as-needed basis.&amp;lt;ref&amp;gt;http://www.ruby-doc.org/core-2.0.0/Enumerator/Lazy.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
=='''How a lazy enumerator works'''==&lt;br /&gt;
A lazy enumerator in Ruby works as both a data consumer and a data producer. To understand how it’s done, we have to understand what an Enumerator::Generator and an Enumerator::Yielder is.&lt;br /&gt;
&lt;br /&gt;
A simple way of creating an enumerable series of data in Ruby is to create an array. However if we want more flexibility in handling each element of the series while generating it, we can do so by using an Enumerator::Generator.&amp;lt;ref&amp;gt;33333333333333&amp;lt;/ref&amp;gt; Consider the example below to create an Enumerator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
even_natural_numbers = Enumerator.new do |yielder|&lt;br /&gt;
	number = 0&lt;br /&gt;
	loop do&lt;br /&gt;
		number += 2&lt;br /&gt;
		yielder.yield number&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here a block with an yielder is passed to the constructor of the enumerator. Everytime the next method of the enumerator is called, the block is executed till the point the yielder is called in the line “yielder.yield number”. The control is passed to the yielder and returned back to the enumerator generator block when the “next” method is called on the enumerator again. &lt;br /&gt;
&lt;br /&gt;
[[File:Enumerator-generator.png‎]]&lt;br /&gt;
&lt;br /&gt;
To understand how the block is executed on each call of “next”, the above code can be modified as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
even_natural_numbers = Enumerator.new do |yielder|&lt;br /&gt;
 number = 0&lt;br /&gt;
 loop do&lt;br /&gt;
   number += 2&lt;br /&gt;
   yielder.yield number&lt;br /&gt;
   puts &amp;quot;continuing loop&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
puts even_natural_numbers.next&lt;br /&gt;
puts even_natural_numbers.next&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
2&lt;br /&gt;
continuing loop&lt;br /&gt;
4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On the first “next” call to ‘even_natural_numbers’, the value of number is 2 and it’s passed to the yielder. During the second “next” call, the execution of the generator block continues from the line ‘puts “continuing loop”’ and the blocks yields again with the value 4.&lt;br /&gt;
&lt;br /&gt;
Printing the above even_natural_numbers object gives the output:&lt;br /&gt;
 #&amp;lt;Enumerator: #&amp;lt;Enumerator::Generator:0x007fbb040b2e28&amp;gt;:each&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows that the enumerator object is created with a reference to an internal object called Enumerator::Generator and the “each” method is setup to call that generator.&lt;br /&gt;
&lt;br /&gt;
In the above example, the enumerator acts as a lazy generator i.e. generating new numbers of the series only on demand. By cascading multiple such lazy enumerators, each enumerator can be made to act as a data generator as well as a consumer. Consider an example where the first 10 even numbers which are also multiples of 5 are to be generated:&lt;br /&gt;
&lt;br /&gt;
If the “select” method is used on the enumerator “even_natural_numbers” as follows, an infinite loop is produced:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
puts even_natural_numbers.select {|v| v%5==0}.first(10)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The reason behind the infinite loop is that the “select” method tries to iterate over the entire collection and doesn’t pass the control to the next method in line unless the collection is exhausted which, in an infinite collection, never happens. Hence it’s necessary to define a lazy version of the select method to do something useful with the infinite range that’s being lazily generated. The code given below adds a lazy version of the “select” method to the existing “Enumerator” class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Enumerator&lt;br /&gt;
 def lazy_select(&amp;amp;block)&lt;br /&gt;
   Enumerator.new do |yielder|&lt;br /&gt;
     self.each do |val|&lt;br /&gt;
       yielder.yield(val) if block.call(val)&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The lazy_select method creates an enumerator which yields to the next method in line on selecting each value that satisfies the condition in the block. Using the lazy_select method on even_natural_numbers won't give an infinte loop anymore. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
puts even_natural_numbers.lazy_select {|v| v%5==0}.first(5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above line of code gives the output as:&lt;br /&gt;
10&lt;br /&gt;
20&lt;br /&gt;
30&lt;br /&gt;
40&lt;br /&gt;
50&lt;br /&gt;
&lt;br /&gt;
The flow of numbers in the above chain of lazy methods can be illustrated as below:&lt;br /&gt;
[[File:Lazy-select.png‎]]&lt;br /&gt;
&lt;br /&gt;
=='''Differences '''==&lt;br /&gt;
If you try to iterate over an infinite range in Enumerator then it will run  into an endless loop while with Enumerator::Lazy you can avoid endless loop and get just the value you need.&amp;lt;ref&amp;gt;http://patshaughnessy.net/2013/4/3/ruby-2-0-works-hard-so-you-can-be-lazy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; range = 1..Float::INFINITY&lt;br /&gt;
&amp;gt; range.collect { |n| n**2}.first(10) #endless loop  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
but with lazy,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; range = 1..Float::INFINITY&lt;br /&gt;
&amp;gt; range.lazy.collect { |n| n**2}.first(10)&lt;br /&gt;
=&amp;gt; [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enumerator::Lazy acts just like the original, but it re-implements methods such as select and map so that they can work with infinite sequences. The lazy versions of the various methods do not return arrays of data. Instead, it returns a new enumerator that includes its own special processing—below example of map method returns an enumerator.&amp;lt;ref&amp;gt;http://patshaughnessy.net/2013/4/3/ruby-2-0-works-hard-so-you-can-be-lazy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; range = 1..100&lt;br /&gt;
&amp;gt; range.map{|n| n**2}.take(10) #returns array&lt;br /&gt;
=&amp;gt; [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
but with lazy,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; range.lazy.map{|n| n**2}.take(10) #returns enumerator&lt;br /&gt;
=&amp;gt;#&amp;lt;Enumerator::Lazy:#&amp;lt;Enumerator::Lazy:#&amp;lt;Enumerator::Lazy:1..100&amp;gt;:map&amp;gt;:take(10)&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Examples '''==&lt;br /&gt;
&lt;br /&gt;
===Example 1===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'date'&lt;br /&gt;
require ‘benchmark’&lt;br /&gt;
Benchmark.bm(8) do |x|&lt;br /&gt;
	x.report(&amp;quot;Non Lazy :&amp;quot;) do&lt;br /&gt;
		puts (Date.new(2015)..Date.new(9999)).select{|d| d.day == 13 and d.friday?}.first(10)&lt;br /&gt;
	end&lt;br /&gt;
	x.report(&amp;quot;Lazy :&amp;quot;) do&lt;br /&gt;
		puts (Date.new(2015)..Date.new(9999)).lazy.select{|d| d.day == 13 and d.friday?}.first(10)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example 2===&lt;br /&gt;
&lt;br /&gt;
This example give you idea of using lazy enumeration in file read example and comparing with non lazy enumeration way&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'benchmark'&lt;br /&gt;
fileName = &amp;quot;C:\\sample.txt&amp;quot;&lt;br /&gt;
Benchmark.bm(8) do |x|&lt;br /&gt;
		x.report(&amp;quot;Non Lazy :&amp;quot;) do&lt;br /&gt;
		50.times { File.readlines(fileName).detect { |line| line =~ /110216/i} }&lt;br /&gt;
		end&lt;br /&gt;
	x.report(&amp;quot;Lazy :&amp;quot;) do&lt;br /&gt;
			50.times { File.open(fileName).lazy.detect { |line| line =~ /110216/i} }&lt;br /&gt;
		end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you deal with large data and start chaining multiple enumeration methods together, the use of lazy evaluation prevents you from using unnecessary amounts of memory in temporary variables which makes lazy evaluation faster than non lazy evaluation. &lt;br /&gt;
&lt;br /&gt;
=='''Drawbacks'''==&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
We have seen usage and benefits of lazy enumeration in above examples but below simple example will give you drawback of it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'benchmark'&lt;br /&gt;
Benchmark.bm(8) do |x|&lt;br /&gt;
	x.report(&amp;quot;Non Lazy :&amp;quot;) do&lt;br /&gt;
		(1..10000000).select { |i| i % 3 == 0 || i % 5 == 0}.reduce(:+)&lt;br /&gt;
	end&lt;br /&gt;
	x.report(&amp;quot;Lazy :&amp;quot;) do&lt;br /&gt;
		(1..10000000).lazy.select { |i| i % 3 == 0 || i % 5 == 0}.reduce(:+)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lazy enumeration is act as a proxy in between program and data so sometimes lazy enumeration gives non negligible performance hit. It is recommended not to use lazy enumeration everywhere as it adds another layer.&amp;lt;ref&amp;gt;https://bugs.ruby-lang.org/issues/6183&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Achandr9</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Lazy-select.png&amp;diff=93539</id>
		<title>File:Lazy-select.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Lazy-select.png&amp;diff=93539"/>
		<updated>2015-02-09T17:30:20Z</updated>

		<summary type="html">&lt;p&gt;Achandr9: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Achandr9</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Lazy_select.png&amp;diff=93538</id>
		<title>File:Lazy select.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Lazy_select.png&amp;diff=93538"/>
		<updated>2015-02-09T17:25:37Z</updated>

		<summary type="html">&lt;p&gt;Achandr9: uploaded a new version of &amp;amp;quot;File:Lazy select.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Achandr9</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Lazy_select.png&amp;diff=93537</id>
		<title>File:Lazy select.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Lazy_select.png&amp;diff=93537"/>
		<updated>2015-02-09T17:24:59Z</updated>

		<summary type="html">&lt;p&gt;Achandr9: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Achandr9</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/ch1a_9_RA&amp;diff=93536</id>
		<title>CSC/ECE 517 Spring 2015/ch1a 9 RA</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/ch1a_9_RA&amp;diff=93536"/>
		<updated>2015-02-09T16:56:07Z</updated>

		<summary type="html">&lt;p&gt;Achandr9: /* How a lazy enumerator works */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Lazy Enumerators&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
In Ruby 1.8 and Ruby 1.9 the problem with enumeration that generate infinite sequences is that we have to write special, non-greedy, versions of methods. But, if you’re using Ruby 2.0 or later, you have this support built in. If you call Enumerator#lazy on any Ruby enumerator, you get back an instance of class Enumerator::Lazy. Many basic class like Array and Hash has lazy method through Enumerator class.&amp;lt;ref&amp;gt;Programming Ruby 1.9 &amp;amp; 2.0 4th Edition&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The lazy methods returns a lazy enumerator whose methods Map/collect, flat_map/ collect_caoncat, select/ find_all, reject, grep, zip, take, #take_while, drop, #drop_while, and cycle enumerate values only on as-needed basis.&amp;lt;ref&amp;gt;http://www.ruby-doc.org/core-2.0.0/Enumerator/Lazy.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
=='''How a lazy enumerator works'''==&lt;br /&gt;
A lazy enumerator in Ruby works as both a data consumer and a data producer. To understand how it’s done, we have to understand what an Enumerator::Generator and an Enumerator::Yielder is.&lt;br /&gt;
&lt;br /&gt;
A simple way of creating an enumerable series of data in Ruby is to create an array. However if we want more flexibility in handling each element of the series while generating it, we can do so by using an Enumerator::Generator.&amp;lt;ref&amp;gt;33333333333333&amp;lt;/ref&amp;gt; Consider the example below to create an Enumerator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
even_natural_numbers = Enumerator.new do |yielder|&lt;br /&gt;
	number = 0&lt;br /&gt;
	loop do&lt;br /&gt;
		number += 2&lt;br /&gt;
		yielder.yield number&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here a block with an yielder is passed to the constructor of the enumerator. Everytime the next method of the enumerator is called, the block is executed till the point the yielder is called in the line “yielder.yield number”. The control is passed to the yielder and returned back to the enumerator generator block when the “next” method is called on the enumerator again. &lt;br /&gt;
&lt;br /&gt;
[[File:Enumerator-generator.png‎]]&lt;br /&gt;
&lt;br /&gt;
To understand how the block is executed on each call of “next”, the above code can be modified as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
even_natural_numbers = Enumerator.new do |yielder|&lt;br /&gt;
 number = 0&lt;br /&gt;
 loop do&lt;br /&gt;
   number += 2&lt;br /&gt;
   yielder.yield number&lt;br /&gt;
   puts &amp;quot;continuing loop&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
puts even_natural_numbers.next&lt;br /&gt;
puts even_natural_numbers.next&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
2&lt;br /&gt;
continuing loop&lt;br /&gt;
4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On the first “next” call to ‘even_natural_numbers’, the value of number is 2 and it’s passed to the yielder. During the second “next” call, the execution of the generator block continues from the line ‘puts “continuing loop”’ and the blocks yields again with the value 4.&lt;br /&gt;
&lt;br /&gt;
Printing the above even_natural_numbers object gives the output:&lt;br /&gt;
 #&amp;lt;Enumerator: #&amp;lt;Enumerator::Generator:0x007fbb040b2e28&amp;gt;:each&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows that the enumerator object is created with a reference to an internal object called Enumerator::Generator and the “each” method is setup to call that generator.&lt;br /&gt;
&lt;br /&gt;
In the above example, the enumerator acts as a lazy generator i.e. generating new numbers of the series only on demand. By cascading multiple such lazy enumerators, each enumerator can be made to act as a data generator as well as a consumer. Consider an example where the first 10 even numbers which are also multiples of 5 are to be generated:&lt;br /&gt;
&lt;br /&gt;
If the “select” method is used on the enumerator “even_natural_numbers” as follows, an infinite loop is produced:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
puts even_natural_numbers.select {|v| v%5==0}.first(10)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The reason behind the infinite loop is that the “select” method tries to iterate over the entire collection and doesn’t pass the control to the next method in line unless the collection is exhausted which, in an infinite collection, never happens. Hence it’s necessary to define a lazy version of the select method to do something useful with the infinite range that’s being lazily generated. The code given below adds a lazy version of the “select” method to the existing “Enumerator” class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Enumerator&lt;br /&gt;
 def lazy_select(&amp;amp;block)&lt;br /&gt;
   Enumerator.new do |yielder|&lt;br /&gt;
     self.each do |val|&lt;br /&gt;
       yielder.yield(val) if block.call(val)&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The lazy_select method creates an enumerator which yields to the next method in line on selecting each value that satisfies the condition in the block. Using the lazy_select method on even_natural_numbers won't give an infinte loop anymore. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
puts even_natural_numbers.lazy_select {|v| v%5==0}.first(5)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above line of code gives the output as:&lt;br /&gt;
10&lt;br /&gt;
20&lt;br /&gt;
30&lt;br /&gt;
40&lt;br /&gt;
50&lt;br /&gt;
&lt;br /&gt;
The flow of numbers in the above chain of lazy methods can be illustrated as below:&lt;br /&gt;
&lt;br /&gt;
=='''Differences '''==&lt;br /&gt;
If you try to iterate over an infinite range in Enumerator then it will run  into an endless loop while with Enumerator::Lazy you can avoid endless loop and get just the value you need.&amp;lt;ref&amp;gt;http://patshaughnessy.net/2013/4/3/ruby-2-0-works-hard-so-you-can-be-lazy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; range = 1..Float::INFINITY&lt;br /&gt;
&amp;gt; range.collect { |n| n**2}.first(10) #endless loop  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
but with lazy,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; range = 1..Float::INFINITY&lt;br /&gt;
&amp;gt; range.lazy.collect { |n| n**2}.first(10)&lt;br /&gt;
=&amp;gt; [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enumerator::Lazy acts just like the original, but it re-implements methods such as select and map so that they can work with infinite sequences. The lazy versions of the various methods do not return arrays of data. Instead, it returns a new enumerator that includes its own special processing—below example of map method returns an enumerator.&amp;lt;ref&amp;gt;http://patshaughnessy.net/2013/4/3/ruby-2-0-works-hard-so-you-can-be-lazy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; range = 1..100&lt;br /&gt;
&amp;gt; range.map{|n| n**2}.take(10) #returns array&lt;br /&gt;
=&amp;gt; [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
but with lazy,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; range.lazy.map{|n| n**2}.take(10) #returns enumerator&lt;br /&gt;
=&amp;gt;#&amp;lt;Enumerator::Lazy:#&amp;lt;Enumerator::Lazy:#&amp;lt;Enumerator::Lazy:1..100&amp;gt;:map&amp;gt;:take(10)&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Examples '''==&lt;br /&gt;
&lt;br /&gt;
===Example 1===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'date'&lt;br /&gt;
require ‘benchmark’&lt;br /&gt;
Benchmark.bm(8) do |x|&lt;br /&gt;
	x.report(&amp;quot;Non Lazy :&amp;quot;) do&lt;br /&gt;
		puts (Date.new(2015)..Date.new(9999)).select{|d| d.day == 13 and d.friday?}.first(10)&lt;br /&gt;
	end&lt;br /&gt;
	x.report(&amp;quot;Lazy :&amp;quot;) do&lt;br /&gt;
		puts (Date.new(2015)..Date.new(9999)).lazy.select{|d| d.day == 13 and d.friday?}.first(10)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example 2===&lt;br /&gt;
&lt;br /&gt;
This example give you idea of using lazy enumeration in file read example and comparing with non lazy enumeration way&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'benchmark'&lt;br /&gt;
fileName = &amp;quot;C:\\sample.txt&amp;quot;&lt;br /&gt;
Benchmark.bm(8) do |x|&lt;br /&gt;
		x.report(&amp;quot;Non Lazy :&amp;quot;) do&lt;br /&gt;
		50.times { File.readlines(fileName).detect { |line| line =~ /110216/i} }&lt;br /&gt;
		end&lt;br /&gt;
	x.report(&amp;quot;Lazy :&amp;quot;) do&lt;br /&gt;
			50.times { File.open(fileName).lazy.detect { |line| line =~ /110216/i} }&lt;br /&gt;
		end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you deal with large data and start chaining multiple enumeration methods together, the use of lazy evaluation prevents you from using unnecessary amounts of memory in temporary variables which makes lazy evaluation faster than non lazy evaluation. &lt;br /&gt;
&lt;br /&gt;
=='''Drawbacks'''==&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
We have seen usage and benefits of lazy enumeration in above examples but below simple example will give you drawback of it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'benchmark'&lt;br /&gt;
Benchmark.bm(8) do |x|&lt;br /&gt;
	x.report(&amp;quot;Non Lazy :&amp;quot;) do&lt;br /&gt;
		(1..10000000).select { |i| i % 3 == 0 || i % 5 == 0}.reduce(:+)&lt;br /&gt;
	end&lt;br /&gt;
	x.report(&amp;quot;Lazy :&amp;quot;) do&lt;br /&gt;
		(1..10000000).lazy.select { |i| i % 3 == 0 || i % 5 == 0}.reduce(:+)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lazy enumeration is act as a proxy in between program and data so sometimes lazy enumeration gives non negligible performance hit. It is recommended not to use lazy enumeration everywhere as it adds another layer.&amp;lt;ref&amp;gt;https://bugs.ruby-lang.org/issues/6183&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Achandr9</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/ch1a_9_RA&amp;diff=93533</id>
		<title>CSC/ECE 517 Spring 2015/ch1a 9 RA</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/ch1a_9_RA&amp;diff=93533"/>
		<updated>2015-02-09T16:46:08Z</updated>

		<summary type="html">&lt;p&gt;Achandr9: /* How a lazy enumerator works */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Lazy Enumerators&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
In Ruby 1.8 and Ruby 1.9 the problem with enumeration that generate infinite sequences is that we have to write special, non-greedy, versions of methods. But, if you’re using Ruby 2.0 or later, you have this support built in. If you call Enumerator#lazy on any Ruby enumerator, you get back an instance of class Enumerator::Lazy. Many basic class like Array and Hash has lazy method through Enumerator class.&amp;lt;ref&amp;gt;Programming Ruby 1.9 &amp;amp; 2.0 4th Edition&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The lazy methods returns a lazy enumerator whose methods Map/collect, flat_map/ collect_caoncat, select/ find_all, reject, grep, zip, take, #take_while, drop, #drop_while, and cycle enumerate values only on as-needed basis.&amp;lt;ref&amp;gt;http://www.ruby-doc.org/core-2.0.0/Enumerator/Lazy.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
=='''How a lazy enumerator works'''==&lt;br /&gt;
A lazy enumerator in Ruby works as both a data consumer and a data producer. To understand how it’s done, we have to understand what an Enumerator::Generator and an Enumerator::Yielder is.&lt;br /&gt;
&lt;br /&gt;
A simple way of creating an enumerable series of data in Ruby is to create an array. However if we want more flexibility in handling each element of the series while generating it, we can do so by using an Enumerator::Generator.&amp;lt;ref&amp;gt;33333333333333&amp;lt;/ref&amp;gt; Consider the example below to create an Enumerator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
even_natural_numbers = Enumerator.new do |yielder|&lt;br /&gt;
	number = 0&lt;br /&gt;
	loop do&lt;br /&gt;
		number += 2&lt;br /&gt;
		yielder.yield number&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here a block with an yielder is passed to the constructor of the enumerator. Everytime the next method of the enumerator is called, the block is executed till the point the yielder is called in the line “yielder.yield number”. The control is passed to the yielder and returned back to the enumerator generator block when the “next” method is called on the enumerator again. &lt;br /&gt;
&lt;br /&gt;
[[File:Enumerator-generator.png‎]]&lt;br /&gt;
&lt;br /&gt;
To understand how the block is executed on each call of “next”, the above code can be modified as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
even_natural_numbers = Enumerator.new do |yielder|&lt;br /&gt;
 number = 0&lt;br /&gt;
 loop do&lt;br /&gt;
   number += 2&lt;br /&gt;
   yielder.yield number&lt;br /&gt;
   puts &amp;quot;continuing loop&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
puts even_natural_numbers.next&lt;br /&gt;
puts even_natural_numbers.next&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
2&lt;br /&gt;
continuing loop&lt;br /&gt;
4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On the first “next” call to ‘even_natural_numbers’, the value of number is 2 and it’s passed to the yielder. During the second “next” call, the execution of the generator block continues from the line ‘puts “continuing loop”’ and the blocks yields again with the value 4.&lt;br /&gt;
&lt;br /&gt;
Printing the above even_natural_numbers object gives the output:&lt;br /&gt;
 #&amp;lt;Enumerator: #&amp;lt;Enumerator::Generator:0x007fbb040b2e28&amp;gt;:each&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows that the enumerator object is created with a reference to an internal object called Enumerator::Generator and the “each” method is setup to call that generator.&lt;br /&gt;
&lt;br /&gt;
In the above example, the enumerator acts as a lazy generator i.e. generating new numbers of the series only on demand. By cascading multiple such lazy enumerators, each enumerator can be made to act as a data generator as well as a consumer. Consider an example where the first 10 even numbers which are also multiples of 5 are to be generated:&lt;br /&gt;
&lt;br /&gt;
If the “select” method is used on the enumerator “even_natural_numbers” as follows, an infinite loop is produced:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
puts even_natural_numbers.select {|v| v%5==0}.first(10)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The reason behind the infinite loop is that the “select” method tries to iterate over the entire collection and doesn’t pass the control to the next method in line unless the collection is exhausted which, in an infinite collection, never happens. Hence it’s necessary to define a lazy version of the select method to do something useful with the infinite range that’s being lazily generated. The code given below adds a lazy version of the “select” method to the existing “Enumerator” class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Enumerator&lt;br /&gt;
 def lazy_select(&amp;amp;block)&lt;br /&gt;
   Enumerator.new do |yielder|&lt;br /&gt;
     self.each do |val|&lt;br /&gt;
       yielder.yield(val) if block.call(val)&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The lazy_select method creates an enumerator which yields to the next method in line on selecting each value that satisfies the condition in the block.&lt;br /&gt;
&lt;br /&gt;
=='''Differences '''==&lt;br /&gt;
If you try to iterate over an infinite range in Enumerator then it will run  into an endless loop while with Enumerator::Lazy you can avoid endless loop and get just the value you need.&amp;lt;ref&amp;gt;http://patshaughnessy.net/2013/4/3/ruby-2-0-works-hard-so-you-can-be-lazy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; range = 1..Float::INFINITY&lt;br /&gt;
&amp;gt; range.collect { |n| n**2}.first(10) #endless loop  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
but with lazy,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; range = 1..Float::INFINITY&lt;br /&gt;
&amp;gt; range.lazy.collect { |n| n**2}.first(10)&lt;br /&gt;
=&amp;gt; [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enumerator::Lazy acts just like the original, but it re-implements methods such as select and map so that they can work with infinite sequences. The lazy versions of the various methods do not return arrays of data. Instead, it returns a new enumerator that includes its own special processing—below example of map method returns an enumerator.&amp;lt;ref&amp;gt;http://patshaughnessy.net/2013/4/3/ruby-2-0-works-hard-so-you-can-be-lazy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; range = 1..100&lt;br /&gt;
&amp;gt; range.map{|n| n**2}.take(10) #returns array&lt;br /&gt;
=&amp;gt; [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
but with lazy,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; range.lazy.map{|n| n**2}.take(10) #returns enumerator&lt;br /&gt;
=&amp;gt;#&amp;lt;Enumerator::Lazy:#&amp;lt;Enumerator::Lazy:#&amp;lt;Enumerator::Lazy:1..100&amp;gt;:map&amp;gt;:take(10)&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Examples '''==&lt;br /&gt;
&lt;br /&gt;
===Example 1===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'date'&lt;br /&gt;
require ‘benchmark’&lt;br /&gt;
Benchmark.bm(8) do |x|&lt;br /&gt;
	x.report(&amp;quot;Non Lazy :&amp;quot;) do&lt;br /&gt;
		puts (Date.new(2015)..Date.new(9999)).select{|d| d.day == 13 and d.friday?}.first(10)&lt;br /&gt;
	end&lt;br /&gt;
	x.report(&amp;quot;Lazy :&amp;quot;) do&lt;br /&gt;
		puts (Date.new(2015)..Date.new(9999)).lazy.select{|d| d.day == 13 and d.friday?}.first(10)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example 2===&lt;br /&gt;
&lt;br /&gt;
This example give you idea of using lazy enumeration in file read example and comparing with non lazy enumeration way&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'benchmark'&lt;br /&gt;
fileName = &amp;quot;C:\\sample.txt&amp;quot;&lt;br /&gt;
Benchmark.bm(8) do |x|&lt;br /&gt;
		x.report(&amp;quot;Non Lazy :&amp;quot;) do&lt;br /&gt;
		50.times { File.readlines(fileName).detect { |line| line =~ /110216/i} }&lt;br /&gt;
		end&lt;br /&gt;
	x.report(&amp;quot;Lazy :&amp;quot;) do&lt;br /&gt;
			50.times { File.open(fileName).lazy.detect { |line| line =~ /110216/i} }&lt;br /&gt;
		end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you deal with large data and start chaining multiple enumeration methods together, the use of lazy evaluation prevents you from using unnecessary amounts of memory in temporary variables which makes lazy evaluation faster than non lazy evaluation. &lt;br /&gt;
&lt;br /&gt;
=='''Drawbacks'''==&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
We have seen usage and benefits of lazy enumeration in above examples but below simple example will give you drawback of it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'benchmark'&lt;br /&gt;
Benchmark.bm(8) do |x|&lt;br /&gt;
	x.report(&amp;quot;Non Lazy :&amp;quot;) do&lt;br /&gt;
		(1..10000000).select { |i| i % 3 == 0 || i % 5 == 0}.reduce(:+)&lt;br /&gt;
	end&lt;br /&gt;
	x.report(&amp;quot;Lazy :&amp;quot;) do&lt;br /&gt;
		(1..10000000).lazy.select { |i| i % 3 == 0 || i % 5 == 0}.reduce(:+)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lazy enumeration is act as a proxy in between program and data so sometimes lazy enumeration gives non negligible performance hit. It is recommended not to use lazy enumeration everywhere as it adds another layer.&amp;lt;ref&amp;gt;https://bugs.ruby-lang.org/issues/6183&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Achandr9</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Enumerator-generator.png&amp;diff=93532</id>
		<title>File:Enumerator-generator.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Enumerator-generator.png&amp;diff=93532"/>
		<updated>2015-02-09T16:44:56Z</updated>

		<summary type="html">&lt;p&gt;Achandr9: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Achandr9</name></author>
	</entry>
</feed>