Functional Programming in Scala, Second Edition (MEAP V08) Michael Pilquist PDF Download
Functional Programming in Scala, Second Edition (MEAP V08) Michael Pilquist PDF Download
https://ebookmeta.com/product/functional-programming-in-scala-
second-edition-meap-v08-michael-pilquist/
https://ebookmeta.com/product/programming-scala-scalability-
functional-programming-objects-third-edition-wampler-dean/
https://ebookmeta.com/product/learning-concurrent-programming-in-
scala-second-edition-aleksandar-prokopec-2/
https://ebookmeta.com/product/learning-concurrent-programming-in-
scala-second-edition-aleksandar-prokopec/
https://ebookmeta.com/product/below-zero-the-steminist-
novellas-3-1st-edition-ali-hazelwood/
Caged an Omegaverse Reverse Harem Romance Golden Cage
Omegas Book 1 1st Edition Mona Black
https://ebookmeta.com/product/caged-an-omegaverse-reverse-harem-
romance-golden-cage-omegas-book-1-1st-edition-mona-black/
https://ebookmeta.com/product/the-lost-dragon-dan-michaelson-d-k-
holmberg/
https://ebookmeta.com/product/blueprint-how-dna-makes-us-who-we-
are-with-a-new-afterword-for-the-paperback-edition-robert-plomin/
https://ebookmeta.com/product/mathematical-methods-in-image-
processing-and-inverse-problems-1st-edition-xue-cheng-tai/
https://ebookmeta.com/product/we-are-not-broken-1st-edition-
nadine-little/
Atlas of Emergency Medicine Procedures 2nd Edition
Latha Ganti
https://ebookmeta.com/product/atlas-of-emergency-medicine-
procedures-2nd-edition-latha-ganti/
Functional Programming in Scala, Second Edition
MEAP V08
1. MEAP_VERSION_8
2. Welcome
3. 1_What_is_functional_programming?
4. 2_Getting_started_with_functional_programming_in_Scala
5. 3_Functional_data_structures
6. 4_Handling_errors_without_exceptions
7. 5_Strictness_and_laziness
8. 6_Purely_functional_state
9. 7_Purely_functional_parallelism
10. 8_Property-based_testing
11. 9_Parser_combinators
12. 10_Monoids
13. 11_Monads
14. 12_Applicative_and_traversable_functors
15. 13_External_effects_and_I/O
16. 14_Local_effects_and_mutable_state
17. 15_Stream_processing_and_incremental_I/O
MEAP VERSION 8
Welcome
Thank you for purchasing the MEAP for Functional Programming in Scala,
Second Edition.
The first edition was published in 2014 and quickly became regarded as a
classic text in functional programming. It's been used by university courses
and by study groups, by hobbyists and the by world's largest companies, and
has been translated to different languages. The first edition also had a
reputation for being very difficult, with many readers getting stuck on some
of the exercises.
A lot has changed in Scala since 2014. At the time of publication, Scala 2.10
had been recently released and the Scala FP ecosystem was in its infancy.
Major open source projects like Doobie (http://github.com/tpolecat/doobie)
and http4s (http://http4s.org) were just getting started, the Cats
(http://typelevel.org/cats/) library didn't yet exist, and FS2
(https://github.com/typelevel/fs2), which grew out of the code presented in
chapter 15, was just published. Interoperability between libraries was
cumbersome and the Scala language had some key limitations that made FP
less accessible than it could be.
The second edition of Functional Programming in Scala does not stray far
from the first edition. We cover the same topics and in the same style,
avoiding teaching any specific library and instead focusing on teaching the
underlying concepts that power libraries like Cats, Doobie, http4s, and FS2.
The text has been updated for the release of Scala 3, as well as other changes
that have occurred in the standard library since the original publication using
Scala 2.10. Perhaps controversially, we've decided to include inline,
annotated answers to the exercises. We hope that by doing so, readers that
were discouraged after getting stuck will instead find the inline answers
illuminating and continue with the text. We encourage all readers to try the
exercises before reading the answers though, as practice with FP concepts is
essential to understanding. The exercises and answers, updated for Scala 3,
are also available on the book's Github repository:
http://github.com/fpinscala/fpinscala on the second-edition branch.
In this book
Modifying a variable
Modifying a data structure in place
Setting a field on an object
Throwing an exception or halting with an error
Printing to the console or reading user input
Reading from or writing to a file
Drawing on the screen
We’ll provide a more precise definition of side effects later in this chapter,
but consider what programming would be like without the ability to do these
things, or with significant restrictions on when and how these actions can
occur. It may be difficult to imagine. How is it even possible to write useful
programs at all? If we can’t reassign variables, how do we write simple
programs like loops? What about working with data that changes, or handling
errors without throwing exceptions? How can we write programs that must
perform I/O, like drawing to the screen or reading from a file?
In this chapter, we’ll look at a simple program with side effects and
demonstrate some of the benefits of FP by removing these side effects. We’ll
also discuss the benefits of FP more generally and define two important
concepts—referential transparency and the substitution model.
class Cafe: #1
def buyCoffee(cc: CreditCard): Coffee = #2
val cup = Coffee() #3
cc.charge(cup.price) #4
cup #5
class CreditCard: #6
def charge(price: Double): Unit = #7
println("charging " + price) #8
class Coffee:
val price: Double = 2.0
val cc = CreditCard() #9
val cafe = Cafe()
val cup = cafe.buyCoffee(cc)
As a result of this side effect, the code is difficult to test. We don’t want our
tests to actually contact the credit card company and charge the card! This
lack of testability is suggesting a design change: arguably, CreditCard
shouldn’t have any knowledge baked into it about how to contact the credit
card company to actually execute a charge, nor should it have knowledge of
how to persist a record of this charge in our internal systems. We can make
the code more modular and testable by letting CreditCard be ignorant of
these concerns and passing a Payments object into buyCoffee.
class Cafe:
def buyCoffee(cc: CreditCard, p: Payments): Coffee =
val cup = Coffee()
p.charge(cc, cup.price)
cup
class CreditCard #1
trait Payments: #2
def charge(cc: CreditCard, price: Double): Unit #3
class SimulatedPayments extends Payments: #4
def charge(cc: CreditCard, price: Double): Unit =
println("charging " + price + " to " + cc)
class Coffee:
val price: Double = 2.0
val cc = CreditCard()
val p = Payments()
val cafe = Cafe()
val cup = cafe.buyCoffee(cc, p)
Separate from the concern of testing, there’s another problem: it’s difficult to
reuse buyCoffee. Suppose a customer, Alice, would like to order 12 cups of
coffee. Ideally we could just reuse buyCoffee for this, perhaps calling it 12
times in a loop. But as it is currently implemented, that will involve
contacting the payment system 12 times, authorizing 12 separate charges to
Alice’s credit card! That adds more processing fees and isn’t good for Alice
or the coffee shop.
The functional solution is to eliminate side effects and have buyCoffee return
the charge as a value in addition to returning the Coffee. The concerns of
processing the charge by sending it off to the credit card company, persisting
a record of it, and so on, will be handled elsewhere. Again, we’ll cover
Scala’s syntax more in later chapters, but here’s what a functional solution
might look like:
class Cafe:
def buyCoffee(cc: CreditCard): (Coffee, Charge) = #1
val cup = new Coffee()
(cup, Charge(cc, cup.price)) #2
Here we’ve separated the concern of creating a charge from the processing or
interpretation of that charge. The buyCoffee function now returns a Charge
as a value along with the Coffee. We’ll see shortly how this lets us reuse it
more easily to purchase multiple coffees with a single transaction. But what
is Charge? It’s a data type we just invented containing a CreditCard and an
amount, equipped with a handy function, combine, for combining charges
with the same CreditCard:
case class Charge(cc: CreditCard, amount: Double): #1
def combine(other: Charge): Charge =
if cc == other.cc then #2
Charge(cc, amount + other.amount) #3
else
throw new Exception("Can't combine charges with different cards") #4
class Cafe:
Making Charge into a first-class value has other benefits we might not have
anticipated: we can more easily assemble business logic for working with
these charges. For instance, Alice may bring her laptop to the coffee shop and
work there for a few hours, making occasional purchases. It might be nice if
the coffee shop could combine these purchases Alice makes into a single
charge, again saving on credit card processing fees. Since Charge is first-
class, we can write the following function to coalesce any same-card charges
in a List[Charge]:
def coalesce(charges: List[Charge]): List[Charge] =
charges.groupBy(_.cc).values.map(_.reduce(_.combine(_))).toList
We’re passing functions as values to the groupBy, map, and reduce methods.
You’ll learn to read and write one-liners like this over the next several
chapters. The _.cc and _.combine(_) are syntax for anonymous functions,
which we’ll introduce in the next chapter. As a preview, _.cc is equivalent to
c => c.cc and _.combine(_) is equivalent to (c1, c2) =>
c1.combine(c2).
You may find this kind of code difficult to read because the notation is very
compact. But as you work through this book, reading and writing Scala code
like this will become second nature to you very quickly. This function takes a
list of charges, groups them by the credit card used, and then combines them
into a single charge per card. It’s perfectly reusable and testable without any
additional mock objects or interfaces. Imagine trying to implement the same
logic with our first implementation of buyCoffee!
This is just a taste of why functional programming has the benefits claimed,
and this example is intentionally simple. If the series of refactorings used
here seems natural, obvious, unremarkable, or standard practice, that’s good.
FP is merely a discipline that takes what many consider a good idea to its
logical endpoint, applying the discipline even in situations where its
applicability is less obvious. As you’ll learn over the course of this book, the
consequences of consistently following the discipline of FP are profound and
the benefits enormous. FP is a truly radical shift in how programs are
organized at every level—from the simplest of loops to high-level program
architecture. The style that emerges is quite different, but it’s a beautiful and
cohesive approach to programming that we hope you come to appreciate.
We saw in the case of buyCoffee how we could separate the creation of the
Charge from the interpretation or processing of that Charge. In general, we’ll
learn how this sort of transformation can be applied to any function with side
effects to push these effects to the outer layers of the program. Functional
programmers often speak of implementing programs with a pure core
and a thin layer on the outside that handles effects.
But even so, surely at some point we must actually have an effect on the
world and submit the Charge for processing by some external system. And
aren’t there other useful programs that necessitate side effects or mutation?
How do we write such programs? As we work through this book, we’ll
Another Random Scribd Document
with Unrelated Content
between the palms of their hands, wound the pieces round sticks in
a spiral fashion, and baked them in front of the fire. A few potatoes
the Maoris had with them were likewise spitted and roasted in this
way. The place where we camped was an exceedingly wild-looking
spot, and during the night we experienced a severe frost, the
thermometer descending to 28°.
We struck our camp at the Mangakino before daylight, and set out
on our journey at once, but, unpleasant to relate, without any
breakfast, as our commissariat was now reduced to a few potatoes,
which we had determined to cook when we should get further on
the road. We rose from the valley of the river on to the level plains
just as the first rays of the sun swept over the country in a flood of
glowing light, and the air was so pure and buoyant that we soon
forgot that we were journeying on an empty stomach, until we came
to a stream, where we found an abundant growth of watercress, of
which we ate heartily, one of the Maoris remarking with a broad grin
that we had at last come "to feed like the cows." When travelling
with the Maoris I could not but admire the easy, good-natured way
in which they took everything—nothing disconcerted them. When
impediments to travel presented themselves, the bigger the
difficulties to overcome, the more ardent they appeared to surmount
them. When crossing the swollen rivers, if one got a bigger ducking
than the rest, they would laugh and joke at the ill-luck of their
comrade, while he in his turn would enjoy the amusement as much
as they did.
On one occasion, when we were ascending a steep, slippery hill, the
saddle-girth of one of the horses broke, and the saddle slipping
aside, the rider fell heavily and rolled down a muddy bank. This
brought down roars of laughter from the others, who told him not to
mind himself, but that it was a pity to spoil a good horse by letting
him know how easily a man could fall off his back.
I always found the natives to be expert and fearless horsemen, and
I believe that a cavalry regiment of well-trained and well-mounted
Maoris, both for courage, endurance, and élan, would form one of
the finest body of troops ever marshalled upon a parade-ground or a
battle-field.
When travelling with them, another interesting fact was that they
seemed to take a pride in being able to define thoroughly all the
natural features of their country. Each mountain and hill had its
special name, and every valley and plain and river, down to the
smallest stream, each being called after some characteristic feature
or legendary tale connected with it; while every tree, plant, bird, and
insect was known by a designation which betokened either its
appearance or habits.
A remarkable feature indicative of the endurance of the natives, was
that one night they would be sleeping in a wharepuni with the
thermometer over 100°, and the next night they would not hesitate
to lie down upon the damp ground with only a blanket over them,
and with the thermometer at several degrees below freezing-point.
It is true we often went through the same ordeal ourselves during
the journey, but it appeared to me to be more remarkable on the
part of the Maoris, as they seemed to enjoy the stifling heat of their
wharepunis as a positive luxury, while we looked upon it as being
very much akin to a sojourn in Hades.
We reached the Waipapa River near its junction with the Mangatete,
and descended from the table-land, over 100 feet, to the crossing-
place. This river, which was one of the largest we had met with,
rushed with a rapid current through a deep rock-bound gorge from
the mountains of Titiraupenga to join the Waikato, of which it
formed one of the principal tributaries. We gained the crossing-place
by a steep, winding descent, the mountains with their rocky bluffs
on the opposite side of the river being clothed with a dense
vegetation of giant trees, while to the right of the track by which we
had to descend was a small mountain forming a complete cone, and
which was clothed from base to summit with a luxuriant growth of
fern and tall manuka. The whole gorge through which the river
wound had a very wild and beautiful appearance, while the water,
like that of the Waikato, into which it fell after crossing the plains,
was as clear as crystal. Beyond the Waipapa we passed through
more open country until we neared the Te Toto ranges, when
mountain, hill, and valley mingled together in a most picturesque
way.
It took us several hours to traverse the Te Toto ranges, the track
winding about in every direction, with deep ravines on either side.
Here the vegetation was of the most luxuriant and varied order, but
the enormous roots of the great trees made riding very difficult.
We crossed the Waipari River, a large stream flowing from the
Rangitoto ranges into the Waikato. The descent to the crossing-place
of this river was no less than 500 feet, and we had to mount a
slippery incline on the opposite side of equal altitude. Our course
now lay over high fern-clad ridges, and now, for the first time, the
broad valley of the Waipa was before us, with Maungatautari to the
north, and Pirongia to the north-west.
Towards sundown we passed along a ridge, with a tremendous rock-
bound gorge beneath us, and where the enormous rocks were
dispersed about in a way which resembled the ruins of a feudal
stronghold. This place was formerly occupied as a pa, and on one
occasion a great battle was fought there by the Ngatiraukawa, who
were defeated by the Ngatituwharetoa and Ngatimatakore, who, it is
said, feasted for days on the bodies of their enemies.
A few miles beyond Tetauranga we arrived at a low hill, upon the
summit of which a number of Maoris were camped in tents. As luck
would have it, feeding was just going on, and we were invited to
partake of a welcome meal. Although it was now evening, we
determined to push on our way, and when the moon rose we
started, and gained the head-waters of the Puniu River, which we
crossed with the intention of camping on the opposite side; we,
however, got wet in the operation, and as the place was swampy,
and the night fearfully cold, we determined to ride several miles
further, to Hengia pa, which we reached at ten o'clock, after a
journey of over sixty miles, and which had kept us in the saddle for
about seventeen hours. Before arrival at the settlement, the whole
country was covered with a white frost, and the damp, chilly cold of
the low valley of the Waipa seemed to go right into the marrow of
one's bones.
The natives appeared much surprised at our nocturnal raid upon
them, but we were soon invited into a whare, where a big fire was
burning, and where four men and an old woman were located with
three or four mongrel dogs. One of the men, although apparently
very old, was yet wiry and active, while his pinched, sharp features
were tattooed in the most elaborate way up to the very roots of his
hair, the thin blue lines forming a complete network over his
countenance. This was the most artistically tattooed savage we had
met on the journey, and Turner remarked to me that he would much
like to have the old man's head to preserve as a mokaikai,[72] but he
was cautious enough not to express this desire to the antiquated
Hauhau.
After we had talked over matters for some time, and the surprise
occasioned by our visit had somewhat abated, our tattooed friend
produced a newly-slaughtered pig from a dark corner of the whare,
and when this was dismembered and some potatoes had been
peeled by the old woman, there was soon a good meal cooking for
our benefit. After we had partaken of our repast, we were invited by
our entertainers to remain the night, and being only too glad to take
advantage of their proffered hospitality, we took up our quarters in a
corner of the primitive whare, which, unpleasant to relate, was
literally alive with fleas.
FOOTNOTES:
[70] For wingless birds, see Appendix.
[71] There were no less than six species of this extinct wingless
bird—
The 11
Giganteus, height
Dinornis feet.
8
" Robustus, " feet
6 in.
6
" Elephantopus " feet
8 in.
5
" Casuarinus " feet
6 in.
5
" Crassus "
feet.
4
" Didiformus " feet
8 in.
[72] Mokaikai, a process of embalming heads, by saturating them
with the pyroligneous acid of wood. This custom was at one time
very common with the Maoris, who thus preserved the heads of
their ancestors, the skin and tattoo marks of the face remaining
perfect for many years.
CHAPTER XXVIII.
THE AUKATI LINE.
POTATAU II.
THE ancestry and tribal connections of Matutaera Te Pukepuke Te
Paue Tu Karato Te-a-Potatau Te Wherowhero Tawhiao, or Potatau II.,
render him the most illustrious and influential chief in New Zealand.
No Maori chief is truly great unless he can trace his descent to some
of those who came in the first canoes from Hawaiki. Tawhiao can do
this, his ancestor being Hotonui, who came in the canoe Tainui, which
made the land at Kawhia. The ancestor, however, who makes the
greatest figure in the history of the family is Tapaue, who had a
number of children who did well in the world, and founded quite a
number of tribes who exist to this day. These children were—Te
Rorokitua, who was the ancestor of the Ngatipaoa, Te Putu, Tahau, Te
Apa, Huiarangi, Ratua, Hikaurua. The son of Te Putu was Tawhia,
whose son was Tuata, whose son was Te Rauanganga, whose son was
Te Wherowhero, whose son was the present Tawhiao. The name of
Tawhiao's mother was Whakaawi, a woman of high birth of the
Ngatimahutu tribe.
Tawhiao's autobiographical narrative is as follows:—
"I was born at a place called Orongokoekoea, at Mokau. The whole of
the Waikatos had been driven from Waikato by the invasion of Hongi,
with his muskets, and the tribes had suffered greatly when the pa was
taken at Matakitaki. The whole of the Waikatos were living at Mokau
when I was born, from fear of Pomare. [The fall of Matakitaki took
place in 1823, and Tawhiao would probably be born a year or two
later.] We did not remain long at Mokau after the death of Pomare. We
came back to Haurua, Kopua, and other places. I lived at Honipaka, in
the Waipa. The Ngatitipa were at Haurau. Te Rauparaha had gone
south long before that time, in prosecution of his conquests at Cook's
Straits. Some of Rauparaha's people, however, the Ngatitoa and
Ngatikoata, came to Matakitaki, and were slain there. Te Waharoa was
then living at Horotiu, and did not move. The Ngapuhi did not attack
him. Pomare made peace with Takurua. Waikato heard that peace had
been made. At this time Te Wherowhero had gone to Taupo. Rauroha
said to Pomare, 'Go back to your own country,' but Pomare would not
consent. Rauroha said, 'You have made peace with me; look at
Matire.' [Matire Toha was subsequently married to Kati, Te
Wherowhero's brother, on the peace-making between Waikato and
Ngapuhi.] Te Wherowhero wished to go to Pomare, but Te Kanawa
resisted his desire, thinking there would be treachery. Pomare insisted
upon going up to Waikato. He was met in battle by the Ngatitipa, the
Ngatitamaoho. Te Aho, a son of Kukutai shot Pomare's fingers off, and
when his people discovered that Pomare was wounded, they fled. The
fight took place at Te Rore, on the Waipa, and the Ngapuhi fled to
Whaingaroa. The chase continued to Te Akau, and as far as Awhitu. I
remember when Matire Toha was brought to Waikato to be married to
Kati. I remember the great crowds that were assembled at the time.
Te Kihirini brought Matire to Waikato. She was very young then. The
first Europeans we saw were at Kawhia. The first I remember was
Captain Kent. The first missionaries in Waikato were Stack, Hamlin,
Williams, and Morgan. The missionaries told us that we should be
burned up unless we believed. I myself was baptized by the name
Matutaera, at Mangere, by Mr. Burrows.
"I remember a European coming to ask Te Wherowhero to sign the
treaty of Waitangi. That European was the missionary, Mr. Maunsell.
[The Ven. Archdeacon Maunsell.] The Maori he had with him was
Tipene Tahatika. Te Wherowhero said he would not sign. Mr. Maunsell
remarked to Tipene, 'This ignorant old man, if he had signed, I would
have given him a blanket.' Te Wherowhero was then at Awhitu. Te
Wherowhero's name was afterwards put to the treaty, but it was
written by Te Kahawai, not by himself. I was at the great meeting at
Remuera. That was when Fitzroy was Governor. The principal speakers
were Wetere te Kauae and Te Katipa. Governor Fitzroy visited Kawhia.
The Rev. Mr. Whiteley and the missionaries had been there long
before that time. When Sir George Grey came, he visited Rangiawhia,
Te Awamutu, and other settlements in Waikato. He had thirty Maoris
as his following. Sir George Grey pointed out Mangere as a place for
Te Wherowhero. He said to my father, 'Come to Mangere, the land is
for you.' I never attended any of the Mission schools."
In reference to the beginning of the New Zealand war, after Te
Wherowhero's death, and when Tawhiao had succeeded his father as
king, he narrates:—
"I was at Rawhitu, a few miles above Rangiriri, when I heard that the
soldiers had crossed the Mangatawhiri. Heta Tarawhiti and a few
others were with me. The Waikatos were then at Rangiriri and other
places. I warned them to avoid the soldiers. When I heard that the
soldiers had crossed the Mangatawhiri, I warned the Maoris to avoid
the soldiers. I told them they should not meet the soldiers on the line
of the Waikato river, but should go inland by Whangamarino to
Paparata, and then to the Kirikiri. [Apparently this was Tawhiao's
military plan, instead of constructing pas on the river, like Meremere
and Rangiriri. If his advice had been taken, the line of our advance,
would have been threatened, and the settlements around Auckland
placed in great danger.] The next thing I heard was that a battle had
been fought at the Koheroa, and that the people I had sent to evade
the soldiers had also gone and fought at the Koheroa. Tapihana was
the chief man whom I had charged. I sent a message also to Mohi
and Ihaaka (occupying the settlement at Pukekohe, the Kirikiri and
adjacent places), telling them to come out from their villages. The
engineer of the pa at Rangiriri, who directed its formation, was Te
Wharepu. I told the people that they should retire to the depth of the
forest to evade the troops. The others would not consent. Te Wharepu
was the leader of the others. They said, 'We will not agree; if our
blood must be shed, let it be shed on our own land at Waikato.' I was
at the fight at Rangiriri. Wiremu Tamehana and myself went to
Rangiriri, and requested the people to move away from that place.
That was the object of both Thompson[74] and myself in going. A
dozen times I tried to persuade them to break up from Rangiriri, but
finding that our efforts were unsuccessful, we left. The balls were
then flying in all directions. I took refuge behind a flax bush. A bullet
passed close to me, and struck the bush. I was not injured. I had a
gun and cartridge-box. I saw some of my people escaping. I told them
to be swift, and move on. They said, 'You must look after yourself; are
you not in danger?' I said, 'No, I will rest a while here.' I took off my
coat and vest, and, after a while, I succeeded in getting on board a
canoe belonging to the Ngatitamaoho, and in making my escape.
Previously ten guns were levelled at me, and a big gun also.
Messengers had gone before, and told the people that I was safe."
FOOTNOTES:
[74] A native known as The King Maker.
THE CHIEFS.
Wiremu Te Wheoro Te Morehu Maipapa comes from a distinguished line
of ancestors. From a woman of celebrity, named Hourua, after whom
the tribe was called, and whose worthy chief was that famous man
Wiremu Te Awatora, of Raglan. Then from the renowned ancestor
Tapoue, Te Wheoro becomes a near relative of Tawhiao, the present
Maori King, which circumstance accounts for the fact of his taking
possession of the Tiwai canoe, which conveyed the late Maori King,
Potatau Te Wherowhero, from Manukau to Ngaruawahia.
The father and mother of Te Wheoro resided in the earlier times at
their settlement, Kaniwhaniwha, on the Waipa River, but, as was the
custom, they would remove to other places, being interested in other
lands, thus verifying the old Maori proverb, "Ka mete kainga tahi; ka
ora kaingarua" (he that has but one home will be subject to failure; he
that has two homes will prosper). The name of Te Wheoro's father
was Te Kaingamata, and his mother's name was Ngapaoa of the
Ngatihinetu tribe of Rangiaowhia. Te Wheoro's grandfather was Te
Whakaete, who was acknowledged to have been of great power
among the Waikatos. Te Whakaete was killed at Maungatautari by the
Ngatipukenga, a war party on its way to Te Wairoa, east coast, and
headed by the chief Naunau. Te Wheoro's own settlement was at Te
Kohekohe, Lower Waikato, and he was always a faithful adherent of
the Europeans. His valuable services were brought into requisition by
General Cameron when war was declared against the Waikatos. The
calamities which befell his people arising out of the war must have
greatly afflicted him, for he tried very hard to divert war during the
Civil Commissionership of Mr. Gorst, M.P., in the Waikato, when Sir
George Grey's Runanga system was introduced, and when the two
Maori newspapers—the Government organ, Te Pihoihoi, and the Maori
King organ, Te Hokioi—were waging a hostile war, which unhappily
culminated in a breach of the peace, Manga Maniapoto having
instructed his partisans to seize the press and type, which was duly