100% found this document useful (5 votes)
41 views55 pages

Complete Ruby Data Processing: Using Map, Reduce, and Select 1st Edition Jay Godse PDF For All Chapters

Data

Uploaded by

eacotthwitat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (5 votes)
41 views55 pages

Complete Ruby Data Processing: Using Map, Reduce, and Select 1st Edition Jay Godse PDF For All Chapters

Data

Uploaded by

eacotthwitat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Experience Seamless Full Ebook Downloads for Every Genre at textbookfull.

com

Ruby Data Processing: Using Map, Reduce, and


Select 1st Edition Jay Godse

https://textbookfull.com/product/ruby-data-processing-using-
map-reduce-and-select-1st-edition-jay-godse/

OR CLICK BUTTON

DOWNLOAD NOW

Explore and download more ebook at https://textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Biota Grow 2C gather 2C cook Loucas

https://textbookfull.com/product/biota-grow-2c-gather-2c-cook-loucas/

textboxfull.com

Earth Systems Data Processing and Visualization Using


MATLAB Zekâi ■en

https://textbookfull.com/product/earth-systems-data-processing-and-
visualization-using-matlab-zekai-sen/

textboxfull.com

Practical Data Science Cookbook Data pre processing


analysis and visualization using R and Python Prabhanjan
Tattar
https://textbookfull.com/product/practical-data-science-cookbook-data-
pre-processing-analysis-and-visualization-using-r-and-python-
prabhanjan-tattar/
textboxfull.com

Python Data Analysis: Perform data collection, data


processing, wrangling, visualization, and model building
using Python 3rd Edition Avinash Navlani
https://textbookfull.com/product/python-data-analysis-perform-data-
collection-data-processing-wrangling-visualization-and-model-building-
using-python-3rd-edition-avinash-navlani/
textboxfull.com
Practical object-oriented design: an agile primer using
Ruby Second Edition Metz

https://textbookfull.com/product/practical-object-oriented-design-an-
agile-primer-using-ruby-second-edition-metz/

textboxfull.com

Data Processing with Optimus: Supercharge big data


preparation tasks for analytics and machine learning with
Optimus using Dask and PySpark Leon
https://textbookfull.com/product/data-processing-with-optimus-
supercharge-big-data-preparation-tasks-for-analytics-and-machine-
learning-with-optimus-using-dask-and-pyspark-leon/
textboxfull.com

Scientific Data Analysis using Jython Scripting and Java


Advanced Information and Knowledge Processing 2010th
Edition Chekanov Sergei V
https://textbookfull.com/product/scientific-data-analysis-using-
jython-scripting-and-java-advanced-information-and-knowledge-
processing-2010th-edition-chekanov-sergei-v/
textboxfull.com

A Common Sense Guide to Data Structures and Algorithms 1st


Edition Jay Wengrow

https://textbookfull.com/product/a-common-sense-guide-to-data-
structures-and-algorithms-1st-edition-jay-wengrow/

textboxfull.com

Processing Big Data with Azure HDInsight: Building Real-


World Big Data Systems on Azure HDInsight Using the Hadoop
Ecosystem 1st Edition Vinit Yadav (Auth.)
https://textbookfull.com/product/processing-big-data-with-azure-
hdinsight-building-real-world-big-data-systems-on-azure-hdinsight-
using-the-hadoop-ecosystem-1st-edition-vinit-yadav-auth/
textboxfull.com
Ruby Data
Processing
Using Map, Reduce, and Select

Jay Godse
Ruby Data Processing
Using Map, Reduce, and Select

Jay Godse
Ruby Data Processing: Using Map, Reduce, and Select
Jay Godse
Kanata, Ontario, Canada

ISBN-13 (pbk): 978-1-4842-3473-0 ISBN-13 (electronic): 978-1-4842-3474-7


https://doi.org/10.1007/978-1-4842-3474-7
Library of Congress Control Number: 2018934400

Copyright © 2018 by Jay Godse


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or
part of the material is concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way,
and transmission or information storage and retrieval, electronic adaptation, computer software,
or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, logo, or image we use the names, logos,
and images only in an editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of opinion as to whether or not
they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of
publication, neither the authors nor the editors nor the publisher can accept any legal
responsibility for any errors or omissions that may be made. The publisher makes no warranty,
express or implied, with respect to the material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Steve Anglin
Development Editor: Matthew Moodie
Coordinating Editor: Mark Powers
Cover designed by eStudioCalamar
Cover image designed by Freepik (www.freepik.com)
Distributed to the book trade worldwide by Springer Science+Business Media New York,
233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505,
email [email protected], or visit www.springeronline.com. Apress Media, LLC is a
California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc
(SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
For information on translations, please email [email protected]; for reprint, paperback, or
audio rights, please email [email protected].
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook
versions and licenses are also available for most titles. For more information, reference our Print
and eBook Bulk Sales web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available
to readers on GitHub via the book's product page, located at www.apress.com/9781484234730.
For more detailed information, please visit http://www.apress.com/source-code.
Printed on acid-free paper
Table of Contents
About the Author����������������������������������������������������������������������������������v
About the Technical Reviewer������������������������������������������������������������vii
Acknowledgments�������������������������������������������������������������������������������ix
Introduction�����������������������������������������������������������������������������������������xi
Prerequisites��������������������������������������������������������������������������������������xv

Chapter 1: Basic Ruby��������������������������������������������������������������������������1


The Command Line�����������������������������������������������������������������������������������������������1
Object Scope���������������������������������������������������������������������������������������������������������3
String��������������������������������������������������������������������������������������������������������������������4
Array���������������������������������������������������������������������������������������������������������������������6
Special Methods����������������������������������������������������������������������������������������������6
Hash����������������������������������������������������������������������������������������������������������������������8
Block-passing Syntax�������������������������������������������������������������������������������������������9
Reading from Files����������������������������������������������������������������������������������������������11

Chapter 2: Function Overview and Simple Examples�������������������������13


Map���������������������������������������������������������������������������������������������������������������������13
Reduce����������������������������������������������������������������������������������������������������������������15
Simple Reduce Examples�����������������������������������������������������������������������������������19
uniq���������������������������������������������������������������������������������������������������������������19
reverse����������������������������������������������������������������������������������������������������������20
max����������������������������������������������������������������������������������������������������������������21
Select������������������������������������������������������������������������������������������������������������������23
iii
Table of Contents

Chapter 3: Complex Solutions������������������������������������������������������������25


Debugging Blocks for Map, Reduce, and Select�������������������������������������������������25
Debugging Map Blocks����������������������������������������������������������������������������������25
Debugging Reduce Blocks�����������������������������������������������������������������������������26
Debugging Select Blocks�������������������������������������������������������������������������������27
FizzBuzz��������������������������������������������������������������������������������������������������������������27
Sum of Odd Cubes����������������������������������������������������������������������������������������������30
Sort a List of Names by Surname�����������������������������������������������������������������������33
Convert a List of Names to CSV��������������������������������������������������������������������������36
Generate a Random List of Names���������������������������������������������������������������������39
Clean a Data Set�������������������������������������������������������������������������������������������������42
Annotate a Sequence of Sales with Running Total����������������������������������������������46
Pascal’s Triangle�������������������������������������������������������������������������������������������������48
Reverse Polish Notation Parser���������������������������������������������������������������������������55
Generate a List of Team Name Bars��������������������������������������������������������������������62
Find Intersection Points of Two Functions����������������������������������������������������������67
Group by Area Code���������������������������������������������������������������������������������������������75
Sliding Window Average��������������������������������������������������������������������������������������77
Denormalize a Data Set��������������������������������������������������������������������������������������82
Pythagorean Triplets�������������������������������������������������������������������������������������������84

Chapter 4: Reverse-Engineering Complex Solutions��������������������������89


Solution for Pascal’s Triangle������������������������������������������������������������������������������90

Index���������������������������������������������������������������������������������������������������97

iv
About the Author
Jay Godse is an active software and web applications developer with
expertise in Ruby, Rails, various databases, and Ansible. He also is
active on Stack Overflow as an active contributor. He graduated with an
engineering degree and then went to work as a digital circuit designer.
After a year of that, he switched to software development, and he has
been there ever since in some form. His early work was mostly real-time
telecommunication device control and provisioning using languages
such as C and Protel. He then transitioned into designing distributed
computing systems using languages such as C++. After that, he moved into
web applications. Along the way, he did stints as a software development
manager and a software architect. But for the last nine years, he has
written web applications in Ruby and DevOps applications in Ansible and
Powershell.

v
About the Technical Reviewer
Massimo Nardone has more than 24 years
of experience in security, web/mobile
development, cloud, and IT architecture. His
true IT passions are security and Android.
He has been programming and teaching
how to program with Android, Perl, PHP, Java,
VB, Python, C/C++, and MySQL for more than
20 years.
He holds a Master of Science in Computing
Science from the University of Salerno, Italy.
He has worked as a project manager, software engineer, research
engineer, chief security architect, information security manager, PCI/SCADA
auditor, and senior lead IT security/cloud/SCADA architect for many years.
Technical skills include security, Android, cloud, Java, MySQL, Drupal,
Cobol, Perl, web and mobile development, MongoDB, D3, Joomla,
Couchbase, C/C++, WebGL, Python, Pro Rails, Django CMS, Jekyll,
Scratch, and more.
He worked as visiting lecturer and supervisor for exercises at the
Networking Laboratory of the Helsinki University of Technology (Aalto
University). He holds four international patents (PKI, SIP, SAML, and Proxy
areas).
He currently works as chief information security officer (CISO) for
Cargotec Oyj and is member of ISACA Finland Chapter Board.
Massimo has reviewed more than 45 IT books for different publishers,
and in addition to reviewing this book he is also the coauthor of
Pro Android Games (Apress, 2015).

vii
Acknowledgments
I would like to acknowledge a few people who helped make me a better
programmer and a better writer. Thanks go to Kevin Szabo and Ronnie
Taylor, both of whom helped me be a better programmer, and to Christina
Hardy, who helped me to become a better writer. And thanks also go to
Mark Powers and the publication team at Apress who helped produce this
book.

ix
Introduction
I wrote mostly reactive software for many years, but there was always
a user interface or reporting component that had string manipulation,
data synthesis, or data formatting. Since I was not trained as a computer
scientist, I did not learn of higher-order functions such as map(), reduce(),
and select() that were found in languages like Lisp or Smalltalk. Also,
Ruby, Python, C++, and JavaScript were not around when I was in school.
As a result, I struggled with cumbersome, error-prone imperative code for
some tasks.
A few years after learning Ruby, but while still using the imperative
programming style for data processing, I discovered the Ruby Enumerable
library and started using its higher-order functions, such as map(),
reduce(), and select(). What happened to my data-processing code?

• Code became more straightforward because data-­


processing tasks could be expressed with a cascading
pipeline of map, reduce, and select stages. Each stage
in the pipeline was simple to develop and debug.

• Code volume was reduced by half.

• Code was naturally more robust, and debugging took


much less time.

• By thinking of solutions in terms of map, reduce, and


select, I was able to envision and solve more complex
problems.

However, I couldn’t find any but the most trivial examples of how to
use these functions to solve data-processing problems. It took me a lot

xi
Introduction

of time-consuming trial and error with map, reduce, and select to solve
these kinds of problems.
I decided to write this book to

• codify my learning and help you understand it more


quickly and effectively than I did; and

• show you my problem-solving approaches to help you


solve your data-processing problems.

I’ll also admit that I was forced to learn many of the programming
nuances of these functions as I wrote the examples.

Who This Book Can Help


This book can help those who

• want to become more skilled in writing data-processing


code by becoming more fluent in using map, reduce
and select;

• are willing to type in all the code in the examples and


run the code using the irb Ruby command line and a
text editor;

• are willing to carefully read and try the examples in this


book and to reflect and ponder the outputs, and even
tweak the programs independently to try to understand
what is happening;

• are open to learning a different way to approach data-­


processing problems; and

• are willing to try failed approaches to learn the nuances


of these functions.

xii
Introduction

Who This Book Might Not Help


This book might not help you if you want

• recipes for standard problems via a cookbook; or

• a reference for data-processing solutions.

xiii
Prerequisites
You should be familiar with some Ruby programming or at least some
programming in another language. If you don’t know Ruby, search out
the book Learn Ruby the Hard Way1 and go through it as prescribed by its
author, Zed Shaw.
If you are fluent with Python, you might benefit from this book if you
go slowly and look up Ruby information online as you move through
this book.
An internet connection helps if you want to search for online help
using Google, Bing, or another search engine.
You should have a computer with Ruby 2.2.x installed. Windows works,
as do Linux and Mac OSX.
You should have a good syntax-highlighting text editor. I recommend
Notepad++ on Windows or gedit on Linux or Macintosh, both of which are
free. Sublime works on Windows, Linux, or Macintosh and is slightly better,
but costs about $70 at the time of this writing.

1
http://learnrubythehardway.org/book/

xv
CHAPTER 1

Basic Ruby
This section will acquaint or refresh you with basic ways to use the Ruby
command line, as well as some relevant Ruby coding.
If you are comfortable programming in Ruby and understand the Ruby
Enumerable Library reasonably well, you can skip this section.

The Command Line


After you install Ruby, you can fire up the interactive command line in
Windows, Linux, or Mac OSX. I’m using Windows.

C:\>  irb
irb(main):001:0>

For brevity, I won’t write the full irb prompt every time.
You can execute Ruby statements line by line. The value returned by
each expression is preceded by ⇒.

irb> a = 4
=> 4
irb> a
=> 4
irb> a + 7
=> 11

© Jay Godse 2018 1


J. Godse, Ruby Data Processing, https://doi.org/10.1007/978-1-4842-3474-7_1
Chapter 1 Basic Ruby

You can choose to put multiple statements on one line, separated by a


semicolon.

irb> list = ["one", "two","three"];1


=>1
irb> list
=>["one", "two", "three"]

You can also have a statement that spans multiple lines.

irb> [2,3,4,5].each do |n|


irb>    if n%2==0
irb>        puts "even"
irb>    else
irb>        puts "odd"
irb>    end
irb> end
=> "even"
=> "odd"
=> "even"
=> "odd"

You can put the code into a file called sample.rb, located in the same
directory or folder from which you ran irb.

1  [2,3,4,5].each do |n|
2      if n%2 == 0
3          puts "even"
4      else
5          puts "odd"
6      end
7  end

2
Chapter 1 Basic Ruby

Then, with irb:

irb> load "sample.rb"


irb> end
=> "even"
=> "odd"
=> "even"
=> "odd"
irb>

You could also copy the code block from your text editor and paste it
directly into your command line and get the same result, as long as you use
only spaces for indentation. (Using tabs for indentation will work fine if
you load the file from the command prompt, but if you paste tabs directly
into irb, it will generate errors).
You can either type the code samples from this book into irb directly
or type them into a text editor and then load the file as just shown.

Object Scope
When you are in a Ruby program, the general method of executing a
method f on an object obj is as follows:

obj.f

That is true whether you are in a Ruby program or the command


line. When code is in the main program file, or in the irb command-line
interpreter, there is an implied context for many functions, such as puts.
That is why you can do this:

puts "Hello world"

You don’t need to specify a class to qualify puts, because puts is a


method of the underlying context object.

3
Chapter 1 Basic Ruby

String
Strings are basic constructs in all languages. Let’s look at a few basic
operations used in this book. Try them out on the irb command line for
yourself.
length or size
This yields the size of the string.
downcase
This converts all letters to lowercase.
upcase
This converts all letters to uppercase.
capitalize
This capitalizes the first letter of a string.
split()
This searches a substring for the argument string
and splits the string into a array comprising
substrings on both sides of the split argument,
while the substring of the split argument is
discarded. If there are no matches, an array is
returned with the whole string:
irb> base_string = "abc def ghi"
irb> base_string.split(" ")
=> ["abc","def","ghi"]
irb> base_string.split(" ")
=> ["abc def","ghi"]
irb> base_string.split(" d")
=> ["abc","ef ghi"]
irb> base_string.split("efghi")
=> ["abc def ghi"]

4
Chapter 1 Basic Ruby

join()

This joins each element of an array of strings with


the string in the join argument as the separator.

irb> stringlist = ["This", "is", "a", "sentence"]


irb> stringlist.join(" ")
=> "This is a sentence"
irb> stringlist.join(",")
=> "This,is,a,sentence"
irb> stringlist.join(" A SPACE ")
=> "This A SPACE is A SPACE a A SPACE sentence"

string interpolation

This lets you define a string template with


parameters. The string #{} gives you a place to put a
variable.

irb> first = "Jack"; last = "Black"


irb> full_name = "#{first} #{last}"
=> "Jack Black"

This is especially useful for iterating over a list:

irb> smith_brothers = ["Terry", "Jerry", "Harry"]


irb> smith_brothers.each{|brother| puts "#{brother} Smith"}
Terry Smith
Jerry Smith
Harry Smith
=> ["Terry", "Jerry", "Harry"]

C/C++ programmers will recognize string


interpolation as being similar to the sprintf
function in the C standard library.

5
Chapter 1 Basic Ruby

Array
Arrays in Ruby are like arrays in other languages. They are a collection of
things indexed by a whole number (e.g., 0,1,2,…). In Ruby, an array can
contain any Ruby object at an index. Array indices in Ruby start at 0.
Arrays implement the Ruby Enumerable interface, so they will have
key methods such as each, map, reduce, select, and others.

Special Methods
compact()

This method on an array gets rid of nil members. For


example:

irb> [1,nil,2,nil,nil,3,nil,[]].compact
=> [1,2,3,[]]

flatten()

This method gets rid of inner arrays to an arbitrary


depth. It is often useful when dealing with nested
map and reduce statements. For example:

irb> [[1,[2,3]],4,[5,6]].flatten
=> [1,2,3,4,5,6]

push()

This method pushes an element onto the end of an


array and returns a new array. For example:

irb> [1,2,3,4,5].push(666)
=> [1,2,3,4,5,666]

6
Chapter 1 Basic Ruby

pop

This method removes the last element of an array


and returns that element and returns a new array.
For example:

irb> the_array = [1,2,3,4,5]


irb> tail = the_array.pop
irb> tail
=> 5
irb> the_array
=> [1, 2, 3, 4]

unshift()

This method pushes an element onto the beginning


of an array and returns a new array. For example:

irb> the_array = [1,2,3,4,5]


irb> the_array.unshift(666)
=> [666, 1, 2, 3, 4, 5]

shift

This method removes the first element of an array


and returns that element and modifies the old array.
For example:

irb> the_array = [1,2,3,4,5]


irb> head = the_array.shift
irb> head
=> 1
irb> the_array
=> [2, 3, 4, 5]

7
Chapter 1 Basic Ruby

Hash
Another term for hash is an “associative array,” or even a “dictionary”,
Hashes are indexed by a key object, and there is a value (another object)
for each key object.

irb> newhash = Hash.new


=> {}
irb> newhash2 = {}
=> {}

These are two ways of creating a new hash. The key of a hash can be
any object or symbol.

irb> newhash = {key1: "some_value", key2: 2}


=> {:key1=> "some_value", :key2=>2}
irb> newhash2 = {}
irb> newhash2[:key1] = "key1_symbol"
irb> newhash2["key1"] = "key3_string"
irb> newhash2[3] = 3
irb> newhash2[:key4] = [4,"44"]
irb> newhash2[[3,"33"]] = "wow"
irb> newhash2
=> {:key1=>"key1_symbol", "key2"=>"key2_string", 2=>1,
:key4=>[4,"44"], [3,"33]=\
"wow" }

The key can be any object, including symbols, strings, numbers,


hashes, arrays, or anything. When iterating through a hash using each or
map, it emits a single array with the key as the first element and the value
as the second element, or it can emit two elements, which are the key and
the value. (Note that inspect is how you can inspect the content of any
object).

8
Chapter 1 Basic Ruby

irb> newhash = {a: 1, b: 2, c: 3}


irb> newhash.each{|e| puts e.inspect}
[:a, 1]
[:b, 2]
[:c, 3]
=> {:a => 1, :b => 2, :c => 3}

irb> newhash.map{|key, value| "The key is #{key} and the value


is #{value}"}

=> ["The key is a and the value is 1", "The key is b and the
value is 2", "The key is c and the value is 3"]

Block-passing Syntax
Ruby is one of many languages that allow lexical closures, otherwise
known (kind of ) as anonymous functions or blocks. These functions are
dynamically created. The function can take the form of a defined function.
For example:

irb> def plus_two(a,b)


irb>    a + b + 2
irb> end
irb> plus_two(3,4)
=> 9

Or, you could define it as follows:

irb> plus_two = ->(a,b) do


irb>    a + b + 2
irb> end

9
Chapter 1 Basic Ruby

Or, you could define it this way:

irb> plus_three = ->(a,b){a + b + 3}


irb> plus_three.call(5,7)
=> 15
Now, anonymous functions or blocks can be passed to other functions
as parameters. A function that takes a function (defined or anonymous)
as a parameter will optionally execute the function in its program flow.
Suppose there is a function called printit() defined as follows:

irb> printit = ->(a) do


irb>    puts a.inspect
irb> end

Now, suppose you want to print each element of a range. You will call
each on the array, which will run the block passed to each for each element
of the array.

irb> (1..5).each(&printit)
1
2
3
4
5
=> (1..5)

You could also pass an actual block of code to run. The block is
surrounded by do and end or { and }. Objects between the vertical bars are
optionally passed to the block (depending on the definition of the block),
and they are used by the block to execute. The return value of a block is the
value of the last expression in the block.

irb> (1..5).each do |num|


irb>    puts num.inspect
irb> end

10
Chapter 1 Basic Ruby

You will get the same output as earlier. Ditto for the following:

irb> (1..5).each{|num| puts num.inspect }

In Ruby, map, reduce, and select all take a code block as a parameter,
and the code block is executed as defined by the function. In this book,
I will use the do-end syntax most often, and sometimes the { } syntax.

Reading from Files


A common operation in data processing is reading from files and writing to
files. Suppose you have names.txt, which looks like this:

1,John
2,Jack
3,Jim
4,Jared
5,John

To read it, you would do the following:

irb> names = File.open("names.txt").read

Now, on some computers, new lines are split by a carriage return


(“\n”), and on other computers lines are split by a line feed and a carriage
return (“\r\n”).
If you want to split this file into rows, you would do the following:

irb> names.split("\n")

That could yield

=>["1,John\r", "2,Jack\r", "3,Jim\r", "4,Jared\r", "5,John\r"]

or

=>["1,John", "2,Jack", "3,Jim", "4,Jared", "5,John"]

11
Chapter 1 Basic Ruby

To ensure consistency, use the chomp method, which removes whitespace


characters if they exist. For example:

irb> "John\r".chomp
=> "John"
irb> "John".chomp
=> "John"

So, for our array, just to ensure that we don’t pick up stray line feeds,
we do the following:

irb> names.split("\n").map{|row| row.chomp}


=>["1,John", "2,Jack", "3,Jim", "4,Jared", "5,John"]

I assume that the examples in this book don’t use “\r\n”, but rather
just “\n”. If that doesn’t work on your operating system, use the chomp()
method as shown before working with the array.

12
CHAPTER 2

Function Overview
and Simple Examples
The Ruby library includes the module Enumerable. This library contains
map(), reduce(), select(), and other functions. This section will outline
the syntax and meanings of the different parts of code that use these three
functions.
If you can get through this section comfortably, both typing the code
into irb and understanding the results, then you will be in a good position
to deepen your understanding with the complex examples and reverse
engineering that follow in the next chapters.

M
 ap
This function of the Ruby Enumerable library is simple but profound. The
map() method is applied to an array or a hash. The job of map() is to apply
a function or block to each member of the array and return a new array.
So, when you see

def f(x)
    x*x
end

© Jay Godse 2018 13


J. Godse, Ruby Data Processing, https://doi.org/10.1007/978-1-4842-3474-7_2
Chapter 2 Function Overview and Simple Examples

output_array =
[1,2,3,4,5].map do |number|
    f(number)
end

you read, for each number in [1,2,3,4,5] apply f(x) to return the array
[f(1), f(2), f(3), f(4), f(5)]. In this case, the answer is [1,4,9,16,25].
One could encode it in traditional imperative programming as follows:

output_array = []
for number in 1..5
    output_array.push( f(number) )
end

Using map, for example:

output_array =
[1,2,3,4,5].map do |number|
    number*number
end

Or, you could encode it as follows:

output_array =
[1,2,3,4,5].map{|element| element*element}

[1,2,3,4,5] is the array. The function (or block) to be applied to each


element is {|element| element*element }.
With the { } syntax, or the do-end syntax, the object in the vertical bars
(represented by element) is the element of the array currently being acted
upon by the block, and the last object in any function or block is the return
value, so element*element is returned. The net result is the following:

[1,4,9,16,25]

14
Chapter 2 Function Overview and Simple Examples

Suppose you wanted to provide data to a graphing program that


plotted the square of the value.

[1,2,3,4,5].map{|element| [element, element*element]}

In this case, each “point” is a tuple (array) with an element and its
square. This returns the following:

[[1,1],[2,4],[3,9],[4,16],[5,25]]

The difference is that the block returns an array each time with the
number and its square, so the result is an array of arrays.
Since map returns an array, you can cascade map calls. For example,
you could have a map block square each element, and then a second map
block add 100. For example:

[1,2,3,4,5].map do |number|
    number*number
end.map do |square|
    square + 100
end

=> [101, 104, 109, 116, 125]

A number of the more complex operations can be solved by cascading


with map calls.

Reduce
This function of the Ruby Enumerable library is more complex than map()
and is quite powerful. The method is applied to a collection (for example,
an array or a hash). The job of reduce() is to apply a function cumulatively
to each member of the collection and then return an object (which could
be an array, a single value, a hash, or anything).

15
Chapter 2 Function Overview and Simple Examples

For example:

[1,2,3,4,5].reduce(0, :+)

This is like saying for each member of the list, add (:+) the member to
memo and save the memo for the next element. The initial value of memo is 0
(the first parameter). Another way to code it is as follows:

memo = 0
[1,2,3,4,5].each{|element| memo = memo.+(element)}

Or, you can pass reduce a block of code to run. The block comes after
the closing parenthesis and is surrounded by a do-end construct, or a {}
construct. The emitted variables are always the memo first and the element
second. (In this case, the initial value of memo is 33).

[1,2,3,4,5].reduce(33) do |memo, element|


    memo.+(element)
end
memo

=> 48

(You don’t have to call them “memo” or “element,” but that is how they
behave). After each iteration, the memo takes the value of the last object in
the block. For example:

[1,2,3,4,5].reduce(33) do |memo, element|


    memo.+(element)
    77.7
end

=> 77.7

This returned 77.7, because that was the last object in the block.

16
Chapter 2 Function Overview and Simple Examples

Another thing to remember is that the memo returned by the block has
to be of the same class as the memo emitted by the reduce function. For
example, when you are using reduce() to build a Hash object, you must
return the whole Hash object:

[1,2,3,4,5].reduce({}) do |memo, element|


    memo[element] = element.to_s
end

IndexError: index 2 out of string

There is an error because the first run of the iteration returned


memo[element], which is a String class, but the input expects it to be a
Hash. To correct it, make sure that the memo of class Hash is explicitly the last
object returned, as follows:

[1,2,3,4,5].reduce({}) do |memo, element|


    memo[element] = element.to_s
    memo
end

=> {1=>"1", 2=>"2", 3=>"3", 4=>"4", 5=>"5"}

This worked because memo is a Hash class and was returned every time.
You can think of the reduce operation as operating on each element
and saving some kind of memo to carry forward to the operation on the
next element. In the preceding example, where you calculate the sum of
five numbers,

[1,2,3,4,5].reduce(0,:+)

or

[1,2,3,4,5].reduce(0) do |memo, element|


    memo + element
end

17
Exploring the Variety of Random
Documents with Different Content
E. Smith, “The Teaching of Arithmetic,” Teachers College Record,
Vol. X, No. 1.
[14] E. L. Thorndike, “Handwriting,” Teachers College Record,
Vol. XI, No. 2; Stone, Arithmetical Abilities and Some of the
Factors Determining them.
[15] Quoted by Johnson in a monograph on “The Problem of
Adapting History to Children in the Elementary School,” Teachers
College Record, Vol. IX, p. 319.
[16] Teachers College Record, Vol. IX, pp. 319-320.
[17] “Stenographic Reports of High School Lessons,” Teachers
College Record, September, 1910, pp. 18-26.
[18] Baldwin, Industrial School Education. A most helpful
discussion of industrial work.
[19] W. S. Jackman, “The Relation of School Organization to
Instruction,” The Social Education Quarterly, Vol. I, pp. 55-69;
Scott, Social Education.
[20] Allen, Civics and Health, p. 53.
[21] Dewey, Moral Principles in Education.
[22] See chapter on Social Phases of the Recitation.
[23] Moral Training in the Public Schools, p. 41. The essay by
Charles Edward Rugh.
[24] Bagley, Classroom Management, Chapter XIV.
[25] See discussion of the study lesson, ante.
[26] McMurry, How to Study, Chapter III.
[27] See ante, Chapter XI.
[28] Adapted from a plan prepared by Lida B. Earhart, Ph.D., for
the author’s syllabus on Theory and Practice of Teaching.
[29] Some discussion of the course of study as an instrument in
supervision is given in the chapter on “The Teacher in Relation to
the Course of Study.”
[30] For a discussion of the doctrine of formal discipline, and for
bibliography, see Thorndike, Educational Psychology, 1903
edition, Chapter VIII; Heck, Mental Discipline.
[31] James E. Russell, “The School and Industrial Life,”
Educational Review, Vol. XXXVIII, pp. 433-450.
[32] E. L. Thorndike, “Handwriting,” Teachers College Record,
Vol. XI, No. 2.
[33] Cubberley, School Funds and their Apportionment; Elliott,
Fiscal Aspects of Education; Strayer, City School Expenditures.
[34] In proceeding to the part of the study that is necessarily
largely composed of tables, it may be well to state the position of
the author regarding the partial interpretations offered in
connection with the tables. It is that the entire tables give by far
the best basis for conclusions; that for a thorough comprehension
of the study they should be read quite as fully as any other part;
and that they should be regarded as the most important source of
information rather than the brief suggestive readings which are
liable to give erroneous impressions, both because of the
limitations of a single interpretation and the lack of space for
anything like full exposition.
[35] M = Median, which is the representation of central tendency
used throughout this study. It has the advantages over the
average of being more readily found, of being unambiguous, and
of giving less weight to extreme or erroneous cases.
[36] For reliability of measures of reasoning ability, see Appendix,
p. 100.
[37] As stated in Part I, p. 17, a score is arbitrarily set at one. The
fact that the zero point is unknown in both reasoning and
fundamentals makes these scores less amenable to ordinary
handling than they might at first thought seem. Hence, entire
distributions are either printed or placed on file at Teachers
College.
[38] For the data from which these calculations were made, see
first column of table XXI, p. 52, and the first columns of tables III
and IV, p. 21. The absence of known zero points makes such
computations inadvisable except in connection with the more
reliable evidence of the preceding table.
[39] And it is the opinion of the author that the chances are much
better that one would get a school with a superior product in
education.
The following pages contain advertisements of Macmillan
books on education, pedagogy, etc.
A Cyclopedia of Education
Edited by PAUL MONROE, Ph.D.
Professor of the History of Education. Teachers College, Columbia University,
Author of “A Text-Book in the History of Education,” “Brief
Course in the History of Education,” etc.

The need of such work is evidenced: By the great mass of varied educational literature
showing an equal range in educational practice and theory; by the growing importance
of the school as a social institution, and the fuller recognition of education as a social
process; and by the great increase in the number of teachers and the instability of
tenure which at the same time marks the profession.
The men who need it are: All teachers, professional men, editors, ministers, legislators, all
public men who deal with large questions of public welfare intimately connected with
education—every one who appreciates the value of a reference work which will give
him the outlines of any educational problem, the suggested solutions, the statistical
information, and in general the essential facts necessary to its comprehension.
Among the departmental Editors associated with Dr. Monroe are Dr. Elmer E. Brown,
U. S. Commissioner of Education, Prof. E. F. Buchner, of Johns Hopkins, Dr. WM. H.
Burnham, Clark University, M. Gabriel Compayré, Inspector-General of Public
Instruction, Paris, France, Prof. Wilhelm Münch, of Berlin University, Germany, Prof.
John Dewey, of Columbia University, Dr. Ellwood P. Cubberly, Stanford University,
Cal., Prof. Foster Watson, of the University College of Wales, Dr. David Snedden,
Commissioner of Education for the State of Massachusetts, and others.

Send for a descriptive circular and list of contributors to Volume I

To be completed in five large octavo volumes, each $5.00

T H E M A C M I L L A N C O M PA N Y
64-66 Fifth Avenue, New York
A LIST OF BOOKS FOR TEACHERS
Published by The Macmillan Company

ADAMS, John. Exposition and Illustration in Teaching.


Cloth. viii + 428 pages. $1.25
ARMSTRONG, Henry E. The Teaching of Scientific Method and Other Papers
on Education.
Cloth. xxvii + 504 pages. $1.75
ARNOLD, Felix. A Text-book of School and Class Management. I. Theory and
Practice.
Cloth. 12mo. xxii + 409 pages. Index. $1.25
II. Administration and Hygiene. Cloth. xii + 292 pages. $1.00
—Attention and Interest. Cloth. viii + 272 pages. $1.00
BAGLEY, William Chandler. Classroom Management: Its Principles and
Technique. By William Chandler Bagley, Director, School of Education,
University Of Illinois.
Cloth. 12mo. xvii + 352 pages. $1.25
—The Educative Process. Cloth. 12mo. xix + 358 pages. $1.25
BROWN, John Franklin. The American High School. By John Franklin Brown,
Ph.D., formerly Professor in Education and Inspector of High Schools for the
State University of Iowa.
Cloth. xii + 498 pages. 12mo. $1.25
BUTLER, Nicholas Murray. The Meaning of Education, and Other Essays
and Addresses. By Nicholas Murray Butler, President of Columbia University.
Cloth. 12mo. xii + 230 pages. $1.00
CHUBB, Percival. The Teaching of English. By Percival Chubb, Principal of
High School Department, Ethical Culture School, New York.
Cloth. 12mo. xvii + 411 pages. $1.00
COLLAR, George, and CROOK, Charles W. School Management and
Methods of Instruction. By George Collar and Charles W. Crook, London.
Cloth. 12mo. viii + 336 pages. $1.00
CRONSON, Bernard. Methods in Elementary School Studies. By Bernard
Cronson, A.B., Ph.D., Principal of Public School No. 3, Borough of Manhattan,
City of New York.
Cloth. 12mo. 167 pages. $1.25
—Pupil Self-Government. Cloth. 12mo. ix + 107 pages. $.90
CUBBERLEY. Syllabus of Lectures on the History of Education. With Selected
Bibliographies and Suggested Readings. By Ellwood P. Cubberley. Second
Edition, revised and enlarged. In two parts.
Part I, v + 129 pages, $1.50 net; Part II, xv + 361 pages, $1.50
Complete in one volume, $2.60
DE GARMO, Charles. Interest and Education. By Charles De Garmo, Professor
of the Science and Art of Education in Cornell University.
Cloth. 12mo. xvii + 230 pages. $1.00
—The Principles of Secondary Education.
Vol. I, Studies. Cloth. 12mo. xii + 299 pages. $1.25
Vol. II, Processes of Instruction. xii + 200 Pages. $1.00
Vol. III, Ethical Training. x + 220 pages. $1.00
DEXTER, Edwin Grant. A History of Education in the United States. By Edwin
Grant Dexter, Professor of Education in the University of Illinois.
Cloth. xxi + 665 pages. 8vo. $2.00
HUEY, Edmund B. The Psychology and Pedagogy of Reading. By Professor
Edmund B. Huey, of the Western University of Pennsylvania.
Cloth. 12mo. xvi + 469 pages. $1.40
JONES, Olive M., LEARY, Eleanor G., and QUISH, Agnes E. Teaching
Children to Study. The Group System applied.
Illustrated. Cloth. viii + 193 pages. 12mo. $.80
KILPATRICK, Van Evrie. Departmental Teaching in Elementary Schools.
Cloth. 12mo. xiii + 130 pages, 16mo. $.60
KIRKPATRICK, Edwin A. Fundamentals of Child Study. By Professor Edwin A.
Kirkpatrick, Principal of State Normal School, Fitchburg, Mass.
Cloth. 12mo. xxi + 384 pages. $1.25
—Genetic Psychology. Cloth, xv + 373 pages. $1.25
LAURIE, S. S. Institutes of Education. 3d ed. Cloth. xii + 391 pages. $1.90
MAJOR, David R. First Steps in Mental Growth. A Series of Studies in the
Psychology of Infancy. By David R. Major, Professor of Education in the Ohio
State University.
Cloth, xiv + 360 pages. 12mo. $1.25

THE McMURRY SERIES Each, cloth, 12mo.


General Method
—The Elements of General Method. By Charles A. McMurry.
323 pages. $.90
—The Method of the Recitation. By Charles A. McMurry and Frank M. McMurry,
Professor of the Theory and Practice of Teaching, Teachers College,
Columbia University.
xi + 329 pages. $.90
Special Method. By Charles A. McMurry.
—Special Method in Primary Reading and Oral Work with Stories.
vii + 103 pages. $.60
—Special Method in the Reading of English Classics.
vi + 254 pages. $.75
—Special Method in Language in the Eight Grades.
viii + 192 pages. $.70
—Special Method in History.
vii + 291 pages. $.75
—Special Method in Arithmetic.
vii + 225 pages. $.70
—Special Method in Geography.
xi + 217 pages. $.70
—Special Method in Elementary Science.
ix + 275 pages. $.75
—Nature Study Lessons for Primary Grades. By Mrs. Lida B. McMurry, with an
Introduction by Charles A. McMurry.
xi + 191 pages. $.60
Course of Study in the Eight Grades.
Vol. I. Grades I to IV. vii + 236 pages. $.75
Vol II. Grades V to VIII. v + 226 pages. $.75
MONROE, Paul. A Brief Course in the History of Education. By Paul Monroe,
Ph.D., Professor in the History of Education, Teachers College, Columbia
University.
Cloth. 8vo. xviii + 409 pages. $1.25

The Philosophy of Education


By HERMAN HARRELL HORNE, Ph.D.
Professor of the History of Philosophy and of the History of Education, New York
University
Cloth, 8vo, xvii + 295 pages, $1.50
A connected series of discussions on the foundations of education in the related
sciences of biology, physiology, sociology, and philosophy, and a thoroughgoing
interpretation of the nature, place, and meaning of education in our world. The newest
points of view in the realms of natural and mental science are applied to the
understanding of educational problems. The field of education is carefully divided, and
the total discussion is devoted to the philosophy of education, in distinction from its
history, science, and art.

The Psychological Principles of Education


By HERMAN HARRELL HORNE, Ph.D.
Cloth, 12mo, xiii + 435 pages, $1.75
The relationship of this book to the author’s “Philosophy of Education” is that, whereas
the first was mostly theory with some practice, this is mostly practice with some theory.
This volume lays the scientific foundations for the art of teaching so far as those
foundations are concerned with psychology. The author is the “middleman” between the
psychologist and the teacher, taking the theoretical descriptions of pure psychology and
transforming them into educational principles for the teacher. In the Introduction the
reader gets his bearings in the field of the science of education. The remainder of the
book sketches this science from the standpoint of psychology, the four parts of the
work, Intellectual Education, Emotional Education, Moral Education, and Religious
Education, being suggested by the nature of man, the subject of education. A special
feature is the attention paid to the education of the emotions and of the will.

Idealism in Education
Or First Principles in the Making of Men and Women
By HERMAN HARRELL HORNE, Ph.D.
Author of “The Philosophy of Education” and “The Psychological Principles of
Education”
Cloth, 12mo, xxi + 183 pages, index, $1.25 by mail, $1.34
Professor Horne here discusses three things which he regards as fundamental in the
building of human character,—Heredity, Environment, and Will. His method of handling
these otherwise heavy subjects, makes the book of interest, even to the general reader.

T H E M A C M I L L A N C O M PA N Y
64-66 Fifth Avenue, New York
By WILLIAM CHANDLER BAGLEY
Director of the School of Education, University of Illinois

Craftsmanship in Teaching
Cloth, 12mo, 247 pages, $1.25
Readers of “The Educative Process” and “Classroom Management” by Director W. C.
Bagley of the University of Illinois will welcome the author’s new book on
“Craftsmanship in Teaching.” The book is made up of a series of addresses given
before educational gatherings, the subject of the first one giving the book its name. In
these addresses the personality of the author is more in evidence than is possible in his
more systematic work, but the same sane, scientific point of view is apparent
throughout.

Classroom Management
Cloth, xvii + 332 pages, $1.25
This book considers the problems that are consequent upon the massing of children
together for purposes of instruction and training. It aims to discover how the unit-group
of the school system—the “class”—can be most effectively handled. The topics
commonly included in treatises upon school management receive adequate attention;
the first day of school; the mechanizing of routine; the daily programme; discipline and
punishment; absence and tardiness, etc.

The Educative Process


Cloth, xix + 358 pages, $1.25
The book aims to prevent a waste of energy on the part of the young teacher by setting
forth a systematic and comprehensive view of the task that is to be accomplished by
the school, with the working principles for the attainment of the end. The best idea for
the author’s plan of treatment can be had from his division of the book. Part I discusses
the function of education and of the school in biological and sociological terms. Part II
continues the same topic from the psychological standpoint. Part III deals with the
functioning of experience in its relation to the educative process. Part IV treats of the
relation of education to the three periods of child-development: the transitional, the
formative, the adolescent. Part V considers educational values and the necessity of
ideals in the educative process, and Part VI concludes with the technique of teaching.

T H E M A C M I L L A N C O M PA N Y
64-66 Fifth Avenue, New York
TRANSCRIBER’S NOTE
Obvious typographical errors and punctuation errors have been corrected after
careful comparison with other occurrences within the text and consultation of
external sources.
Some hyphens in words have been silently removed, some added, when a
predominant preference was found in the original book.
Except for those changes noted below, all misspellings in the text, and
inconsistent or archaic usage, have been retained.
Pg 69: ‘a singe problem’ replaced by ‘a single problem’.
Pg 113: ‘Professon Johnson’ replaced by ‘Professor Johnson’.
Pg 136: ‘find situtions’ replaced by ‘find situations’.
Pg 150: ‘actally demanded’ replaced by ‘actually demanded’.
Pg 189: ‘was comformable’ replaced by ‘was conformable’.
Pg 236: ‘genuine motive’ replaced by ‘genuine motives’.
Pg 244: ‘I. Abstract.’ replaced by ‘II. Abstract.’.
Pg 258: The note ‘Footnotes on opposite page.’ has been removed from the
bottom of TABLE III.
Pg 260: ‘XXII’ (first row in the table) replaced by ‘XXIII’.
Pg 272: ‘Syntax of etymology’ replaced by ‘Syntax or etymology’.
Pg 273: ‘c.’ inserted in front of ‘The Influence of the’.
*** END OF THE PROJECT GUTENBERG EBOOK A BRIEF
COURSE IN THE TEACHING PROCESS ***

Updated editions will replace the previous one—the old editions


will be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States copyright
in these works, so the Foundation (and you!) can copy and
distribute it in the United States without permission and without
paying copyright royalties. Special rules, set forth in the General
Terms of Use part of this license, apply to copying and
distributing Project Gutenberg™ electronic works to protect the
PROJECT GUTENBERG™ concept and trademark. Project
Gutenberg is a registered trademark, and may not be used if
you charge for an eBook, except by following the terms of the
trademark license, including paying royalties for use of the
Project Gutenberg trademark. If you do not charge anything for
copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such
as creation of derivative works, reports, performances and
research. Project Gutenberg eBooks may be modified and
printed and given away—you may do practically ANYTHING in
the United States with eBooks not protected by U.S. copyright
law. Redistribution is subject to the trademark license, especially
commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG
LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the


free distribution of electronic works, by using or distributing this
work (or any other work associated in any way with the phrase
“Project Gutenberg”), you agree to comply with all the terms of
the Full Project Gutenberg™ License available with this file or
online at www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand,
agree to and accept all the terms of this license and intellectual
property (trademark/copyright) agreement. If you do not agree to
abide by all the terms of this agreement, you must cease using
and return or destroy all copies of Project Gutenberg™
electronic works in your possession. If you paid a fee for
obtaining a copy of or access to a Project Gutenberg™
electronic work and you do not agree to be bound by the terms
of this agreement, you may obtain a refund from the person or
entity to whom you paid the fee as set forth in paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only


be used on or associated in any way with an electronic work by
people who agree to be bound by the terms of this agreement.
There are a few things that you can do with most Project
Gutenberg™ electronic works even without complying with the
full terms of this agreement. See paragraph 1.C below. There
are a lot of things you can do with Project Gutenberg™
electronic works if you follow the terms of this agreement and
help preserve free future access to Project Gutenberg™
electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright
law in the United States and you are located in the United
States, we do not claim a right to prevent you from copying,
distributing, performing, displaying or creating derivative works
based on the work as long as all references to Project
Gutenberg are removed. Of course, we hope that you will
support the Project Gutenberg™ mission of promoting free
access to electronic works by freely sharing Project
Gutenberg™ works in compliance with the terms of this
agreement for keeping the Project Gutenberg™ name
associated with the work. You can easily comply with the terms
of this agreement by keeping this work in the same format with
its attached full Project Gutenberg™ License when you share it
without charge with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.

1.E. Unless you have removed all references to Project


Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project
Gutenberg™ work (any work on which the phrase “Project
Gutenberg” appears, or with which the phrase “Project
Gutenberg” is associated) is accessed, displayed, performed,
viewed, copied or distributed:

This eBook is for the use of anyone anywhere in the United


States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it
away or re-use it under the terms of the Project Gutenberg
License included with this eBook or online at
www.gutenberg.org. If you are not located in the United
States, you will have to check the laws of the country where
you are located before using this eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is


derived from texts not protected by U.S. copyright law (does not
contain a notice indicating that it is posted with permission of the
copyright holder), the work can be copied and distributed to
anyone in the United States without paying any fees or charges.
If you are redistributing or providing access to a work with the
phrase “Project Gutenberg” associated with or appearing on the
work, you must comply either with the requirements of
paragraphs 1.E.1 through 1.E.7 or obtain permission for the use
of the work and the Project Gutenberg™ trademark as set forth
in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is


posted with the permission of the copyright holder, your use and
distribution must comply with both paragraphs 1.E.1 through
1.E.7 and any additional terms imposed by the copyright holder.
Additional terms will be linked to the Project Gutenberg™
License for all works posted with the permission of the copyright
holder found at the beginning of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files
containing a part of this work or any other work associated with
Project Gutenberg™.
1.E.5. Do not copy, display, perform, distribute or redistribute
this electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the
Project Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must, at
no additional cost, fee or expense to the user, provide a copy, a
means of exporting a copy, or a means of obtaining a copy upon
request, of the work in its original “Plain Vanilla ASCII” or other
form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™
works unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or


providing access to or distributing Project Gutenberg™
electronic works provided that:

• You pay a royalty fee of 20% of the gross profits you derive from
the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt that
s/he does not agree to the terms of the full Project Gutenberg™
License. You must require such a user to return or destroy all
copies of the works possessed in a physical medium and
discontinue all use of and all access to other copies of Project
Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project


Gutenberg™ electronic work or group of works on different
terms than are set forth in this agreement, you must obtain
permission in writing from the Project Gutenberg Literary
Archive Foundation, the manager of the Project Gutenberg™
trademark. Contact the Foundation as set forth in Section 3
below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on,
transcribe and proofread works not protected by U.S. copyright
law in creating the Project Gutenberg™ collection. Despite
these efforts, Project Gutenberg™ electronic works, and the
medium on which they may be stored, may contain “Defects,”
such as, but not limited to, incomplete, inaccurate or corrupt
data, transcription errors, a copyright or other intellectual
property infringement, a defective or damaged disk or other
medium, a computer virus, or computer codes that damage or
cannot be read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES -


Except for the “Right of Replacement or Refund” described in
paragraph 1.F.3, the Project Gutenberg Literary Archive
Foundation, the owner of the Project Gutenberg™ trademark,
and any other party distributing a Project Gutenberg™ electronic
work under this agreement, disclaim all liability to you for
damages, costs and expenses, including legal fees. YOU
AGREE THAT YOU HAVE NO REMEDIES FOR NEGLIGENCE,
STRICT LIABILITY, BREACH OF WARRANTY OR BREACH
OF CONTRACT EXCEPT THOSE PROVIDED IN PARAGRAPH
1.F.3. YOU AGREE THAT THE FOUNDATION, THE
TRADEMARK OWNER, AND ANY DISTRIBUTOR UNDER
THIS AGREEMENT WILL NOT BE LIABLE TO YOU FOR
ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE
OR INCIDENTAL DAMAGES EVEN IF YOU GIVE NOTICE OF
THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If


you discover a defect in this electronic work within 90 days of
receiving it, you can receive a refund of the money (if any) you
paid for it by sending a written explanation to the person you
received the work from. If you received the work on a physical
medium, you must return the medium with your written
explanation. The person or entity that provided you with the
defective work may elect to provide a replacement copy in lieu
of a refund. If you received the work electronically, the person or
entity providing it to you may choose to give you a second
opportunity to receive the work electronically in lieu of a refund.
If the second copy is also defective, you may demand a refund
in writing without further opportunities to fix the problem.

1.F.4. Except for the limited right of replacement or refund set


forth in paragraph 1.F.3, this work is provided to you ‘AS-IS’,
WITH NO OTHER WARRANTIES OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR
ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of
damages. If any disclaimer or limitation set forth in this
agreement violates the law of the state applicable to this
agreement, the agreement shall be interpreted to make the
maximum disclaimer or limitation permitted by the applicable
state law. The invalidity or unenforceability of any provision of
this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the


Foundation, the trademark owner, any agent or employee of the
Foundation, anyone providing copies of Project Gutenberg™
electronic works in accordance with this agreement, and any
volunteers associated with the production, promotion and
distribution of Project Gutenberg™ electronic works, harmless
from all liability, costs and expenses, including legal fees, that
arise directly or indirectly from any of the following which you do
or cause to occur: (a) distribution of this or any Project
Gutenberg™ work, (b) alteration, modification, or additions or
deletions to any Project Gutenberg™ work, and (c) any Defect
you cause.

Section 2. Information about the Mission of


Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new
computers. It exists because of the efforts of hundreds of
volunteers and donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like