Reactive Programming with Kotlin First Edition Learn Rx with RxJava RxKotlin and RXAndroid Alex Sullivan download
Reactive Programming with Kotlin First Edition Learn Rx with RxJava RxKotlin and RXAndroid Alex Sullivan download
https://textbookfull.com/product/reactive-programming-with-
kotlin-first-edition-learn-rx-with-rxjava-rxkotlin-and-rxandroid-
alex-sullivan/
https://textbookfull.com/product/reactive-programming-with-
rxjava-creating-asynchronous-event-based-applications-1st-
edition-tomasz-nurkiewicz-ben-christensen/
https://textbookfull.com/product/reactive-programming-with-
angular-and-ngrx-learn-to-harness-the-power-of-reactive-
programming-with-rxjs-and-ngrx-extensions-1st-edition-oren-farhi-
auth/
https://textbookfull.com/product/kotlin-apprentice-second-
edition-beginning-programming-with-kotlin-irina-galata/
https://textbookfull.com/product/reactive-programming-with-
javascript-1st-edition-hayward-jonathan/
Programming Kotlin Applications Building Mobile and
Server Side Applications with Kotlin 1st Edition Brett
Mclaughlin
https://textbookfull.com/product/programming-kotlin-applications-
building-mobile-and-server-side-applications-with-kotlin-1st-
edition-brett-mclaughlin/
https://textbookfull.com/product/programming-android-with-kotlin-
achieving-structured-concurrency-with-coroutines-pierre-olivier-
laurence/
https://textbookfull.com/product/rxswift-reactive-programming-
with-swift-1st-edition-florent-pillet/
https://textbookfull.com/product/rxswift-reactive-programming-
with-swift-third-edition-raywenderlich-tutorial-team/
https://textbookfull.com/product/scala-reactive-programming-
build-scalable-functional-reactive-microservices-with-akka-play-
and-lagom-1st-edition-rambabu-posa/
Reactive Programming with Kotlin
Notice of Rights
All rights reserved. No part of this book or corresponding materials (such as text,
images, or source code) may be reproduced or distributed by any means without prior
written permission of the copyright owner.
Notice of Liability
This book and all corresponding materials (such as source code) are provided on an “as
is” basis, without warranty of any kind, express of implied, including but not limited to
the warranties of merchantability, fitness for a particular purpose, and
noninfringement. In no event shall the authors or copyright holders be liable for any
claim, damages or other liability, whether in action of contract, tort or otherwise,
arising from, out of or in connection with the software or the use of other dealing in the
software.
Trademarks
All trademarks and registered trademarks appearing in this book are the property of
their own respective owners.
raywenderlich.com 2
Reactive Programming with Kotlin
Dedications
"To my wonderful partner Pallavi, without whom I would have never
been able to start this undertaking. Your support and encouragement
mean the world to me."
— Alex Sullivan
raywenderlich.com 3
Reactive Programming with Kotlin
Vijay Sharma is the final pass editor of this book. Vijay is a husband,
a father and a senior mobile engineer. Based out of Canada's capital,
Vijay has worked on dozens of apps for both Android and iOS. When
not in front of his laptop, you can find him in front of a TV, behind a
book, or chasing after his kids. You can reach out to him on Twitter
@vijaysharm or on LinkedIn @vijaysharm
Manda Frederick is the editor of this book. She has been involved in
publishing for over ten years through various creative, educational,
medical and technical print and digital publications, and is thrilled to
bring her experience to the raywenderlich.com family as Managing
Editor. In her free time, you can find her at the climbing gym,
backpacking in the backcountry, hanging with her dog, working on
poems, playing guitar and exploring breweries.
raywenderlich.com 4
Reactive Programming with Kotlin
Ellen Shapiro is a tech editor for this book. Ellen is an iOS developer
for Bakken & Bæck's Amsterdam office who also occasionally writes
Android apps. She has worked in her spare time to help bring iOS
songwriting app Hum to life. She’s also developed several
independent applications through her personal company, Designated
Nerd Software. When she's not writing code, she's usually tweeting
about it at @DesignatedNerd.
raywenderlich.com 5
Reactive Programming with Kotlin
raywenderlich.com 6
Reactive Programming with Kotlin
Acknowldegments
We'd also like to thank the RxSwift: Reactive Programming with Swift authors, whose
work served as the basis for parts of this book:
• Scott Gardner has been developing iOS apps since 2010, Swift since the day it was
announced, and RxSwift since before version 1. He's authored several video courses,
tutorials, and articles on iOS app development, presented at numerous conferences,
meetups, and online events, and this is his second book. Say hello to Scott on Twitter
at @scotteg.
• Junior Bontognali has been developing on iOS since the first iPhone and joined the
RxSwift team in the early development stage. Based in Switzerland, when he's not
eating cheese or chocolate, he's doing some cool stuff in the mobile space, without
denying to work on other technologies. Other than that he organizes tech events,
speaks and blogs. Say hello to Junior on Twitter at @bontoJR.
• Florent Pillet has been developing for mobile platforms since the last century and
moved to iOS on day 1. He adopted reactive programming before Swift was
announced and has been using RxSwift in production since 2015. A freelance
developer, Florent also uses Rx on Android and likes working on tools for developers
like the popular NSLogger when he's not contracting for clients worldwide. Say hello
to Florent on Twitter at @fpillet.
• Marin Todorov is one of the founding members of the raywenderlich.com team and
has worked on seven of the team's books. Besides crafting code, Marin also enjoys
blogging, teaching, and speaking at conferences. He happily open-sources code. You
can find out more about Marin at www.underplot.com.
raywenderlich.com 7
Reactive Programming with Kotlin
raywenderlich.com 8
Reactive Programming with Kotlin
raywenderlich.com 9
Reactive Programming with Kotlin
Chapter 2: Observables . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
What is an observable? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Lifecycle of an observable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Creating observables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Subscribing to observables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Disposing and terminating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
The create operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Creating observable factories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Using other observable types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
raywenderlich.com 10
Reactive Programming with Kotlin
Key points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Chapter 3: Subjects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
What are subjects? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Working with publish subjects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Working with behavior subjects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Working with replay subjects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Working with async subjects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Working with the RxRelay library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Challenge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Key points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Where to go from here? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
raywenderlich.com 11
Reactive Programming with Kotlin
raywenderlich.com 12
Reactive Programming with Kotlin
raywenderlich.com 13
Reactive Programming with Kotlin
raywenderlich.com 14
Reactive Programming with Kotlin
raywenderlich.com 15
Reactive Programming with Kotlin
raywenderlich.com 16
Reactive Programming with Kotlin
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
raywenderlich.com 17
L Book License
By purchasing Reactive Programming with Kotlin, you have the following license:
• You are allowed to use and/or modify the source code in Reactive Programming with
Kotlin in as many apps as you want, with no attribution required.
• You are allowed to use and/or modify all art, images and designs that are included in
Reactive Programming with Kotlin in as many apps as you want, but must include this
attribution line somewhere inside your app: “Artwork/images/designs: from Reactive
Programming with Kotlin, available at www.raywenderlich.com”.
• The source code included in Reactive Programming with Kotlin is for your personal use
only. You are NOT allowed to distribute or sell the source code in Reactive
Programming with Kotlin without prior authorization.
• This book is for your personal use only. You are NOT allowed to sell this book
without prior authorization, or distribute it to friends, coworkers or students; they
would need to purchase their own copies.
All materials provided with this book are provided on an “as is” basis, without warranty
of any kind, express or implied, including but not limited to the warranties of
merchantability, fitness for a particular purpose and noninfringement. In no event shall
the authors or copyright holders be liable for any claim, damages or other liability,
whether in an action or contract, tort or otherwise, arising from, out of or in connection
with the software or the use or other dealings in the software.
All trademarks and registered trademarks appearing in this guide are the properties of
their respective owners.
raywenderlich.com 18
B Book Source Code &
Forums
This book comes with the source code for the starter and completed projects for each
chapter. These resources are shipped with the digital edition you downloaded from
https://store.raywenderlich.com/products/reactive-programming-with-kotlin.
We’ve also set up an official forum for the book at forums.raywenderlich.com. This is a
great place to ask questions about the book or to submit any errors you may find.
raywenderlich.com 19
W What You Need
To follow along with the tutorials in this book, you’ll need the following:
• IntelliJ IDEA Community 2019.1 or later: IntelliJ IDEA is the IDE upon which
Android Studio is based, and it's used in the book to look at pure Kotlin projects that
demonstrate techniques in RxJava. You can download the latest version of IntelliJ
IDEA Community for free here: https://www.jetbrains.com/idea/
• JDK 8 or later: You'll need a Java Development Kit installed for use with IntelliJ
IDEA projects (Android Studio will use its own version of the JDK). You can download
the Oracle JDK from here: https://www.oracle.com/technetwork/java/javase/
downloads/index.html
• Android Studio 3.3.2 or later: Android Studio is the main development tool for
Android. You can download the latest version of Android Studio for free here:
https://developer.android.com/studio
All the Android sample projects in this book will work just fine in an Android emulator
bundled with Android Studio, or you can also use a physical Android device.
raywenderlich.com 20
B Book Updates
Since you’ve purchased the digital edition version of this book, you get free access to
any updates we may make to the book!
The best way to get update notifications is to sign up for our monthly newsletter. This
includes a list of the tutorials that came out on raywenderlich.com that month, any
important news like book updates or new books, and a list of our favorite iOS
development links for that month. You can sign up here:
• www.raywenderlich.com/newsletter
raywenderlich.com 21
A About the Cover
The common starling, pictured on the cover of this book, seems just that: common. It
isn't particularly large — roughly only 8 inches long. It isn't particularly musical and is
considered noisy in flocks and communal roosts. It's also not particularly beautiful,
with dark glossy feathers and a subtle metallic sheen.
And, yet, this simple bird continues to hold our attention, even being referenced in
literature as early as Shakespeare. Why?
First, it has a talent for mimicry and, like the reactive sensibilities explored in this book,
is highly responsive to its environment. It has up to 20 distinct imitations of other
birds, and it is even known to mimic ringing phones and car alarms.
While we can't know how these birds evolved to this level of cooperation and
responsiveness, we hope to draw some inspiration from them in this book as we guide
you through developing your own reactive programming.
raywenderlich.com 22
Section I: Getting Started with
RxJava
In this part of the book, you’re going to learn about the basics of RxJava. You are going
to have a look at what kinds of asynchronous programming problems RxJava addresses,
and what kind of solutions it offers.
Further, you will learn about the few basic classes that allow you to create and observe
event sequences, which are the foundation of the Rx framework.
You are going to start slow by learning about the basics and a little bit of theory. Please
don't skip these chapters! This will allow you to make good progress in the following
sections when things get more complex.
Chapter 2: Observables
Chapter 3: Subjects
raywenderlich.com 23
1 Chapter 1: Hello, RxJava!
By Alex Sullivan & Marin Todorov
This book aims to introduce you, the reader, to the RxJava, RxKotlin and RxAndroid
libraries and to writing reactive Android apps with Kotlin.
However, just because RxJava doesn't need to be completely rewritten to work in Kotlin
doesn't mean that it couldn't benefit from all of the great features in the Kotlin
programming language.
That's where RxKotlin comes into play. RxKotlin is a library that expands RxJava by
adding a ton of utilities and extension methods that make working with RxJava much
more pleasant in Kotlin. However, you absolutely do not need RxKotlin to use the
RxJava library in a Kotlin-based Android app.
raywenderlich.com 24
Reactive Programming with Kotlin Chapter 1: Hello, RxJava!
That’s the goal of this book: to gradually introduce you to the various RxJava APIs and
Rx concepts by explaining how to use each of the APIs, and then covering their
practical usage in Android apps.
You’ll start with the basic features of RxJava, and then gradually work through
intermediate and advanced topics. Taking the time to exercise new concepts
extensively as you progress will make it easier to master RxJava by the end of the book.
Rx is too broad of a topic to cover completely in a single book; instead, we aim to give
you a solid understanding of the library so that you can continue developing Rx skills
on your own.
We still haven’t quite established what RxJava is though, have we? Start with a simple,
understandable definition and progress to a better, more expressive one as we waltz
through the topic of reactive programming later in this chapter.
As an Android app developer, this should be much more clear and tell you more about
what RxJava is, compared to the first definition you read earlier in this chapter.
Even if you’re still fuzzy on the details, it should be clear that RxJava helps you write
asynchronous code. And you know that developing good, deterministic, asynchronous
code is hard, so any help is quite welcome!
raywenderlich.com 25
Reactive Programming with Kotlin Chapter 1: Hello, RxJava!
Introduction to asynchronous
programming
If you tried to explain asynchronous programming in a simple, down-to-earth
language, you might come up with something along the lines of the following:
An Android app, at any moment, might be doing any of the following things and more:
• Playing audio
All of these things seemingly happen at the same time. Whenever the keyboard
animates out of the screen, the audio in your app doesn’t pause until the animation has
finished, right?
All the different bits of your program don’t block each other’s execution. Android offers
you several different APIs that allow you to perform different pieces of work on
different threads and perform them across the different cores of the device’s CPU.
Writing code that truly runs in parallel, however, is rather complex, especially when
different bits of code need to work with the same pieces of data. It’s hard to determine
which piece of code updates the data first or which code has read the latest value.
• AsyncTask: To do some work on the background and then update elements in your UI
with the result of that background work. You have to make sure to properly handle
cancelling a running AsyncTask when your Activity or Fragment shuts down, since
you could otherwise get a NullPointerException when the AsyncTask tries to update
UI elements that don't exist anymore.
raywenderlich.com 26
Reactive Programming with Kotlin Chapter 1: Hello, RxJava!
• Thread: To start background work in a purely Java way without interacting with any
Android APIs. Threads come with the downside of being expensive and not bound to
any sort of ThreadPool.
• Future: To clearly chain work which will complete at some undetermined point in
the future. Futures are considerably clearer to use than AsyncTasks, but run into
some of the same problems around null pointers when a Fragment or Activity has
been destroyed.
The above isn't an exhaustive list — there's also Handler, JobScheduler, WorkManager,
HandlerThread and Kotlin coroutines.
Many comparisons have been made between using RxJava and using coroutines for
Android development. Each review will give you a different answer about which tool
you should use.
If you're simply looking for an easy way to replace AsyncTask, then coroutines may
make more sense than pulling RxJava into your application. However, if you do want to
move towards a reactive, event-driven architecture, then RxJava is your best bet!
raywenderlich.com 27
Reactive Programming with Kotlin Chapter 1: Hello, RxJava!
After all, your app’s code runs differently depending on various external factors, such as
user input, network activity, or other OS events. Each time the user fires up your app,
the code may run in a completely different order depending on those external factors.
(Well, except for the case when you have an army of robots testing your app, then you
can expect all events to happen with precise, kill-bot synchronization.)
We’re definitely not saying that writing good asynchronous code is impossible. After all,
there's a litany of tools — like the ones listed above — that Android developers have
been using to write asynchronous apps since well before RxJava hit the scene.
The issue is that complex asynchronous code becomes very difficult to write in part
because of the variety of APIs that you as an Android developer will end up using:
You may be using an AsyncTask to update your UI, an IntentService to save something
to a database, a WorkManager task to sync your app to a server, and other various
asynchronous APIs. Since there is no universal language across all the asynchronous
APIs, reading and understanding the code, and reasoning about its execution, becomes
difficult.
To wrap up this section and put the discussion into a bit more context, you’ll compare
two pieces of code: one synchronous and one asynchronous.
Synchronous code
Performing an operation for each element of a list is something you’ve done plenty of
times. It’s a very simple yet solid building block of app logic because it guarantees two
things: It executes synchronously, and the collection is immutable from the outside
world while you iterate over it.
raywenderlich.com 28
Reactive Programming with Kotlin Chapter 1: Hello, RxJava!
Take a moment to think about what this implies. When you iterate over a collection,
you don’t need to check that all elements are still there, and you don’t need to rewind
back in case another thread inserts an element at the start of the collection. You
assume you always iterate over the collection in its entirety at the beginning of the loop.
If you want to play a bit more with these aspects of the for loop, try this in an app or
IntelliJ IDEA project:
Is list mutable inside the for body? Does the collection that the loop iterates over ever
change? What’s the sequence of execution of all commands? Can you modify number if
you need to? You may be surprised by what you see if you run this code.
Asynchronous code
Consider similar code, but assume each iteration happens as a reaction to a click on a
button. As the user repeatedly clicks on the button, the app prints out the next element
in a list:
if (currentIndex != list.lastIndex) {
currentIndex++
}
}
Think about this code in the same context as you did for the previous one. As the user
clicks the button, will that print all of the list's elements? You really can’t say. Another
piece of asynchronous code might remove the last element, before it’s been printed.
Or another piece of code might insert a new element at the start of the collection after
you’ve moved on.
Also, you assume only that the click listener will ever change currentIndex, but another
piece of code might modify currentIndex as well — perhaps some clever code you
added at some point after crafting the above function.
You’ve likely realized that some of the core issues with writing asynchronous code are:
a) the order in which pieces of work are performed and b) shared mutable data.
raywenderlich.com 29
Discovering Diverse Content Through
Random Scribd Documents
sides face the cardinal points, it rose in four equal stories to a height
of nearly two hundred feet, having a summit platform of about two
hundred feet square.[IX-13] Humboldt in 1803 found the four terraces
tolerably distinct, especially on the western slope; Evans in 1870
found the lower terrace quite perfect, but the others traceable only
in a few places without excavation.
The material of which the mound was constructed is adobes, or sun-
dried bricks, generally about fifteen inches long, laid very regularly
with alternate layers of clay. From its material comes the name
Tlalchihualtepec, 'mountain of unburnt bricks,' which has been
sometimes applied to Cholula. An old tradition relates that the
adobes were manufactured at Tlalmanalco, and brought several
leagues to their destination by a long line of men, who handed them
along singly from one to another. Humboldt thought some of the
bricks might have been slightly burned. Respecting the material
which constitutes the alternate layers between the bricks, called clay
by Humboldt, there seems to be some difference of opinion between
different explorers. Col. Brantz Mayer, a careful investigator, says the
adobes are interspersed with small fragments of porphyry and
limestone; and Mr Tylor speaks of them as cemented with mortar
containing small stones and pottery. Evans tells us that the material
is adobe bricks and layers of lava, still perfect in many places. The
historian Veytia by a personal examination ascertained the material
to be "small stones of the kind called guijarros, and a kind of bricks
of clay and straw," in alternate layers.[IX-14] Beaufoy claims to have
found the pyramid faced with small thin hewn stones, one of which
he carried away as a relic—a very wonderful discovery certainly,
when we consider that other very trustworthy explorers, both
preceding and following Beaufoy, found nothing of the kind. Mr
Heller could not find the stone facing, but, as he says, he did find a
coating of mortar as hard as stone, composed of lime, sand, and
water.[IX-15] Many visitors have believed that the pyramid is only
partially artificial, the adobe-work having been added to a smaller
natural hill. This is, however, a mere conjecture, and there are
absolutely no arguments to be adduced for or against it. The truth
can be ascertained only by the excavation of a tunnel through the
mound at its base, or, at least, penetrating to the centre. It is very
remarkable that such an excavation has never been made, either in
the interests of scientific exploration or of treasure-seeking.
Bernal Diaz, at the time of the Conquest, counted a hundred and
twenty steps in a stairway which led up the slope to the temple, but
no traces of such a stairway have been visible in more modern
times. There are traditions among the natives, as is usually the case
in connection with every work of the antiguos, of interior galleries
and apartments of great extent within the mound; such rumors are
doubtless without foundation. The Puebla road cuts off a corner of
the lower terrace, and the excavation made in building the road not
only showed clearly the regular interior construction of the pyramid,
but also laid bare a tomb, which contained two skeletons with two
idols in basalt, a collection of pottery, and other relics not preserved
or particularly described, although the remains of the tomb itself
were examined by Humboldt. The sepulchre was square, with stone
walls supported by cypress beams. The dimensions are not given,
but the apartment is said to have had no traces of any outlet.
Humboldt claims to have discovered a peculiar arrangement of the
adobes about this tomb, by which the pressure on its roof was
diminished.
It is very evident that the pyramid of Cholula contains nothing in
itself to indicate its age, but from well-defined and doubtless reliable
traditions, we may feel very sure that its erection dates back to an
epoch preceding the tenth century, and probably preceding the
seventh. Humboldt shows that it is larger at the base than any of the
old-world pyramids, over twice as large as that of Cheops, but only
slightly higher than that of Mycerinus. "The construction of the
teocalli recalls the oldest monuments to which the history of the
civilization of our race reaches. The temple of Jupiter Bélus, which
the mythology of the Hindus seems to designate by the name of
Bali, the pyramids of Meïdoùm and Dahchoùr, and several of the
group of Sakharah in Egypt, were also immense heaps of bricks, the
remains of which have been preserved during a period of thirty
centuries down to our day."[IX-16]
The historical annals of aboriginal times, confirmed by the Spanish
records of the Conquest, leave no doubt that the chief object of the
pyramid was to support a temple; the discovery of the tomb with
human remains may indicate that it served also for burial purposes.
It is by no means certain, however, that the mound was in any sense
a monument reared over the two bodies whose skeletons were
found; for besides the position of the skeletons in a corner of the
pyramid, indicating in itself the contrary, there is the possibility that
the bodies were those of slaves sacrificed during the process of
building, and deposited here from some superstitious motive. It will
require the discovery of tombs near the centre of this immense
mound to prove that it was erected with any view to use as the
burial place of kings or priests.[IX-17] Wilson, always a sceptic on
matters connected with Mexican aboriginal civilization, pronounces
the pyramid of Cholula "the finest Indian mound on this continent;
where the Indians buried the bravest of their braves, with bows and
arrows, and a drinking cup, that they might not be unprovided for
when they should arrive at the hunting-grounds of the great spirit."
"It is sufficiently wasted by time to give full scope to the imagination
to fill out or restore it to almost any form. One hundred years ago,
some rich citizen constructed steps up its side, and protected the
sides of his steps from falling earth by walls of adobe, or mud-brick;
and on the west side some adobe buttresses have been placed to
keep the loose earth out of the village street. This is all of mans
labor that is visible, except the work of the Indians in shaving away
the hill which constitutes this pyramid. As for the great city of
Cholula, it never had an existence."[IX-18] At a short distance from
the foot of the large pyramid, two smaller ones are mentioned by
several visitors; one of which is doubtless a portion of the chief
mound separated by the road that has been already mentioned. One
of them is described by Beaufoy as having perpendicular sides, and
built of adobes nine inches square and one inch thick; the second
was much smaller and had a corn-patch on its summit. Cuts of the
two small mounds are given by the same explorer. Bullock claims to
have found on the top of one of the detached masses a ditch and
wall forming a kind of figure-eight-formed enclosure one hundred
feet long, in which were many human bones. Evans has a theory
that the small mounds were formed of the material taken from the
larger one in shaping its terraces. Latrobe says that many ruined
mounds may be seen from the summit; in fact, that the whole
surface of the surrounding plain is broken by both natural and
artificial elevations. Ampère was led by his native guide, through a
misunderstanding, to a flat-topped terraced hill, still bearing traces
of a pavement, at a locality called Zapotecas.[IX-19]
The only miscellaneous Cholulan relics of which I find a mention, are
three described by Dupaix and sketched by Castañeda. They were, a
stone head, said to have originally been the top of a column; a
quadrangular block, with incised hieroglyphics on one of its faces;
and a mask of green jasper, reported to have been dug from the
pyramid.[IX-20]
Coat of Arms—Cuernavaca.
Boulder-Sculptures at Cuernavaca.
Eagle of Cuernavaca.
Very near the foot of the northern slope are the entrances to two
tunnels or galleries, one of which terminates at a distance of eighty-
two feet; at least, it was obstructed and could not be explored
beyond that point. The second gallery, cut in the solid limestone of
the hill, about nine feet and a half wide and high, has several
branches running in different directions, some of them terminated by
fallen débris, others apparently walled up intentionally. The floors
are paved to the thickness of a foot and a half with brick-shaped
blocks of stone, the walls are also in many places supported by
masonry, and both pavement, walls, and ceiling are covered with
lime cement, which retains its polish and shows traces in some parts
of having had originally a coating of red ochre. The principal gallery,
after turning once at a right angle, terminates at a distance of
several hundred feet in a large apartment about eighty feet long, in
which two circular pillars are left in the living rock to support the
roof. The accompanying cut is Castañeda's ground plan of the
galleries and subterranean apartment, a being the entrance on the
north; b the termination of main gallery; c, k, the branch gallery; e
and d, obstructed passages; g, g, the room and f, f, the pillars. The
scale of the plan is about fifty feet to the inch, but the dimensions,
according to the scale, are doubtless inaccurate. According to the
plan the galleries are only a little over four feet wide; and the
apartment thirty-three by thirty-nine feet. Alzate's plan agrees with it
so far as it goes; the Revista gives no plan, and its description differs
in some respects, so far as the arrangement of the galleries is
concerned, from the cut.[IX-36] In the top of the room at the south-
east corner, at h, is a dome-like structure, a vertical section of which
is shown at j of the preceding cut, six feet in diameter and six feet
high, lined with stone hewn in curved blocks, with a round hole
about ten inches in diameter extending vertically upward from the
top. It has been generally believed that this passage leads up to the
pyramid on the top of the hill, to be described later; but it will be
seen that if the hill be two miles in circumference, or even half that
size, the galleries are not nearly long enough to reach the centre
under the pyramid. Nebel fancied that the hole in the cupola was so
situated that the rays of the sun twice a year would penetrate from
above and strike an altar in the subterranean hall. The natives report
other passages in the hill besides the one described, and believe that
one of them leads to Chapultepec, near the city of Mexico.
Passing now from the interior to the outer
THE HILL OF
FLOWERS.
surface of the 'hill of flowers,' we find it covered
from top to bottom with masonry. Five terraces,
paved with stone and mortar, and supported by perpendicular walls
of the same material, extend in oval form entirely round the whole
circumference of the hill, one above the other. Neither the width of
the paved platforms nor the height of the supporting walls has been
given by any explorer, but each terrace, with the corresponding
intermediate slope, constitutes something over seventy feet of the
height of the hill. The terrace platforms have sometimes been
described, without any authority, as a paved way leading round and
round the hill in a spiral course to the summit. Dupaix speaks of a
road about eight feet wide, which leads to the summit, but no other
explorer mentions any traces of the original means of ascent. Each
terrace wall, while forming in general terms an ellipse, does not
present a regular line, but is broken into various angles like the
bastions of a fortification. The pavements all slope slightly towards
the south-west, thus permitting the water to run off readily.
According to the plans of Alzate and Castañeda there are two
additional terraces where a spur projects from the hill at the north-
eastern base. Latrobe is the only authority on the intermediate
slopes between the terraces, which he says are occupied with
platforms, bastions, and stages one above another. It is evident from
all accounts that the whole surface of the hill, very likely shaped to
some extent artificially, was covered with stone work, and that
defense was one object aimed at by the builders. The Revista
represents the terrace platforms as additionally fortified by the
perpendicular supporting walls projecting upward above their level,
forming what may perhaps be termed a kind of parapet.
On the summit is a level platform measuring two hundred and
eighty-five by three hundred and twenty-eight feet.[IX-37] According
to Alzate, Humboldt, Dupaix, and other early authorities—except
Nebel, who is silent on the subject—this plaza is surrounded by a
wall. Dupaix says the wall is built of stones without mortar, is five
feet and a half high, and two feet and nine inches thick. Alzate
represents the wall as perpendicular only on the inner side, being in
fact a projection of the upper terrace slope, forming a kind of
parapet, and making the plaza a sunken area. Latrobe also speaks of
the plaza as a hollow square, and Alzate's representation is probably
a correct one; for the author of the account in the Revista says that
the wall described by previous visitors could not be found; and
moreover, that there was no room for it on the north between the
central pyramid and "one of the solid stone masses, or caballeros,
that surround the platform," the caballeros, which may perhaps in
this connection be translated 'parapets,' being doubtless the same
structures that the others describe as a wall.
In this plaza, cultivated in later years as a
PYRAMID OF
XOCHICALCO.
cornfield, there are several mounds and heaps of
stones not particularly described; and near the
centre is a pyramid, or rather the lower story of one, with
rectangular base, the sides of which, exactly or very nearly facing
the cardinal points, measure sixty-five feet from east to west, and
fifty-eight feet from north to south. The lower story, which in some
parts is still standing to its full height, is divided into what may be
termed plinth, frieze, and cornice, and is about sixteen feet high.[IX-
38]
Pyramid of Xochicalco.
Pyramid of Xochicalco.
REMAINS IN THE
SOUTH-EAST.
Sculptured stone—Casasano.
Coiled Serpent—Xochimilco.
Sculptured Stones—Xochimilco.
Sculptured Vase—Tlahuac.
Animal in Stone—Tlalmanalco.
Terra-Cotta Idol—Culhuacan.
Culhuacan, on the north-eastern bank of the same lake, is a small
village which retains the name of the city which once occupied the
site, famous in the annals of Toltec times. Veytia tells us that in his
time some vestiges of the ancient capital were still visible; and
Gondra describes a clay idol found at Culhuacan, and shown in the
cut, as an image of Quetzalcoatl, giving, however, no very clear
reasons for his belief. This relic is fourteen inches high, thirteen
inches wide, and is preserved in the Mexican Museum.[IX-48]
The relics discovered in Anáhuac at points westward from the lakes,
I shall describe without specifying in my text the exact locality of
each place referred to. At Chapultepec there is a tradition that
statues representing Montezuma and Axayacatl were carved in the
living rock of the cliff; and these rock portraits are said to have
remained many years after the Conquest, having been seen by the
distinguished Mexican scientist Leon y Gama. Brasseur de Bourbourg
even claims to have seen traces of them, but this may perhaps be
doubted. One was destroyed at the beginning of the eighteenth
century by order of the over-religious authorities; but the other
remained in perfect preservation until the year 1753, when it also
fell a victim to anti-pagan barbarism. The immense cypresses or
ahuehuetes that still stand at the foot of Chapultepec, 'hill of the
grasshopper,' are said to have been large and flourishing trees
before the coming of the Spaniards.[IX-49]
A few miles from the celebrated church of
HILL OF
OTONCAPOLCO.
Nuestra Señora de los Remedios, is a terraced
stone-faced hill, similar perhaps in its original
condition to Xochicalco, except that the terraces are more numerous
and only three or four feet high. Although, only a short distance
from the capital in an easily accessible locality, only two writers have
mentioned its existence—Alzate y Ramirez in 1792 and Löwenstern
in 1838. The former calls the hill Otoncapolco, and his article in the
Gaceta de Literatura is mainly devoted to proving that this was the
point where Cortés fortified himself after the 'noche triste,' instead of
the hill on which the church of Remedios stands, as others in
Alzate's time believed. The author, who visited the place with an
artist, says, "I saw ruins, and hewn stones of great magnitude, all of
which proves to the eye that this was a fortification, or as the
historians say, a temple, because they thought that everything made
by the Indians had some connection with idolatry; it is sure that in
the place where the celebrated sanctuary stands, there is not found
the slightest vestige of fortress or temple, while on the contrary, all
this is observed at Otoncapolco." This with the remark that this
monument, although not comparable to Xochicalco, yet merits
examination, is all the information Padre Alzate gives us; and
Löwenstern adds but little to our knowledge of the monument. He
found débris of sculptured stone, obsidian, vases, and pottery; also
the ruins of a castle two-thirds up the slope, in connection with
which was found a flat stone over six feet long, bearing a sculptured
five-branched cross—a kind of coat of arms. The hill is from two
hundred and sixty to three hundred and twenty-five feet high, has a
square summit platform, and the whole surface of its slopes was
covered with stone-work, now much displaced, in the shape of
steps, or terraces, between three and four feet high. At one point
the explorer found, as he believed, the entrance to a subterranean
passage, into which he did not enter but inserted a pole about nine
feet.[IX-50]
At Tacuba, the ancient Tlacopan, Bradford mentions the "ruins of an
ancient pyramid, constructed with layers of unburnt brick," and
Löwenstern speaks of broken pottery and fragments of obsidian. The
latter author also claims to have seen near the church of Guadalupe
the foundations of many small dwellings which constituted an
aboriginal city.[IX-51] At Malinalco, near Toluca, two musical
instruments, tlamalhuilili, are mentioned. They were carved from
hard wood and had skin stretched across one end, being three feet
long and eighteen inches in diameter.[IX-52] Mr Foster gives a cut of
a tripod vase in the Chicago Academy of Sciences, which was dug up
near San José. "It is very symmetrically moulded, and is ornamented
by a series of chevrons or small triangles. This chevron mode of
ornamentation appears to have been widely prevalent."[IX-53]
THE CALENDAR-
STONE.
Aztec Calendar-Stone.
The stone has been for many years built into the wall of the
cathedral at the base, where it is exposed to the view of all passers-
by, and to the action of the elements. While lying uncovered in the
plaza it was considerably mutilated by the natives, who took the
opportunity of manifesting their horror of the ancient gods, by
pelting with stones this relic of their paganism. Parts of the stone
were also broken off when it was thrown down and buried by the
conquistadores. Fortunately the sculptured portions have been but
slightly injured, and are shown in the cut. The plates published by
Gama, Humboldt, Nebel, Mayer, and others, are all tolerably
accurate; except that they were drawn to represent the stone
correctly on the plate or block, and of course reversed in printing.
The origin of this error is probably to be found in the fact that nearly
all have copied Gama's plate. In my cut the error is corrected and
the sculptured figures agree exactly with Charnay's photograph.[IX-
55] These figures are the symbols of the Aztec calendar, many of
which are well understood, while others are of unknown or disputed
signification. The calendar has been sufficiently explained in a
preceding volume, and I shall not enter upon its elucidation here.
The sculpture is in low relief, very accurately worked, and the circle
which encloses it projects, according to Mayer, seven inches and a
half, according to Gama and Nebel about three inches, and the rim
of the circle is also adorned with sculptures not shown in the cut.
Respecting the excellence of the sculpture Humboldt says: "the
concentric circles, the divisions, and the subdivisions without number
are traced with mathematical exactitude; the more we examine the
details of this sculpture, the more we discover this taste for
repetitions of the same forms, this spirit of order, this sentiment of
symmetry, which, among half-civilized peoples, take the place of the
sentiment of the beautiful."
No stone like that from which the Calendar-Stone is hewn, is found
within a radius of twenty-five or thirty miles of Mexico, and this may
be regarded as the largest block which the natives are known to
have moved over a long distance. Prescott tells us that the stone
was brought from the mountains beyond Lake Chalco, and was
dropped into the water while being transported across one of the
causeways. There is no reason to attribute this monument to any
nation preceding the Aztecs, although the calendar itself was the
invention of an older people. Wax models of this and other relics,
described by Mr Tylor as very inaccurate, are sold in Mexico; and a
plaster cast, taken by Mr Bullock in 1823, was exhibited in London.
[IX-56]
Sacrificial Stone—Mexico.
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.
textbookfull.com