Get Functional Programming in C#: How To Write Better C# Code 1st Edition Enrico Buonanno Free All Chapters
Get Functional Programming in C#: How To Write Better C# Code 1st Edition Enrico Buonanno Free All Chapters
com
https://textbookfull.com/product/functional-
programming-in-c-how-to-write-better-c-
code-1st-edition-enrico-buonanno/
textbookfull
More products digital (pdf, epub, mobi) instant
download maybe you interests ...
https://textbookfull.com/product/functional-python-programming-
use-a-functional-approach-to-write-succinct-expressive-and-
efficient-python-code-3rd-edition-lott/
https://textbookfull.com/product/effective-c-an-introduction-to-
professional-c-programming-1st-edition-robert-c-seacord/
https://textbookfull.com/product/learn-c-by-example-covers-
versions-11-to-23-final-release-1-converted-edition-frances-
buontempo/
https://textbookfull.com/product/introduction-to-programming-
with-c-1st-edition-nhce/
Modern C++ for Absolute Beginners: A Friendly
Introduction to C++ Programming Language and C++11 to
C++20 Standards 1st Edition Slobodan Dmitrovi■
https://textbookfull.com/product/modern-c-for-absolute-beginners-
a-friendly-introduction-to-c-programming-language-
and-c11-to-c20-standards-1st-edition-slobodan-dmitrovic/
https://textbookfull.com/product/c-programming-complete-guide-to-
learn-the-basics-of-c-programming-in-7-days-2nd-edition-xavier-s-
martin/
https://textbookfull.com/product/functional-programming-in-
javascript-how-to-improve-your-javascript-programs-using-
functional-techniques-first-edition-luis-atencio/
https://textbookfull.com/product/functional-programming-in-
javascript-how-to-improve-your-javascript-programs-using-
functional-techniques-1-edition-edition-luis-atencio/
https://textbookfull.com/product/101-challenges-in-c-
programming-1st-edition-yashavant-kanetkar/
Functional Programming in C#: How to
write better C# code
Enrico Buonanno
Copyright
For online information and ordering of this and other Manning books, please visit
www.manning.com. The publisher offers discounts on this book when ordered in quantity. For
more information, please contact
Special Sales Department
Manning Publications Co.
20 Baldwin Road
PO Box 761
Shelter Island, NY 11964
Email: [email protected]
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any
form or by means electronic, mechanical, photocopying, or otherwise, without prior written
permission of the publisher.
Many of the designations used by manufacturers and sellers to distinguish their products are
claimed as trademarks. Where those designations appear in the book, and Manning Publications
was aware of a trademark claim, the designations have been printed in initial caps or all caps.
Recognizing the importance of preserving what has been written, it is Manning’s policy to
have the books we publish printed on acid-free paper, and we exert our best efforts to that end.
Recognizing also our responsibility to conserve the resources of our planet, Manning books are
printed on paper that is at least 15 percent recycled and processed without the use of elemental
chlorine.
ISBN 9781617293955
1 2 3 4 5 6 7 8 9 10 – EBM – 22 21 20 19 18 17
Dedication
To the little monkey...
Brief Table of Contents
Copyright
Table of Contents
Preface
Acknowledgments
1. Core concepts
2. Becoming functional
3. Advanced techniques
Chapter 11. Lazy computations, continuations, and the beauty of monadic composition
Index
List of Figures
List of Tables
List of Listings
Table of Contents
Copyright
Table of Contents
Preface
Acknowledgments
1. Core concepts
Exercises
Summary
Exercises
Summary
objects
3.2.1. Primitive types are often not specific enough
3.3.2. Bridging the gap between Action and Func with Unit
Exercises
Summary
Introducing functors
Exercises
Summary
Summary
2. Becoming functional
Exercises
Summary
7.5.2. Modularity in FP
Exercises
Summary
Exercises
Summary
Exercises
Summary
Chapter 10. Event sourcing: a functional approach to persistence
domain?Summary
3. Advanced techniques
Chapter 11. Lazy computations, continuations, and the beauty of monadic composition
Summary
Summary
13.3. Combining asynchrony and validation (or any other two monadic effects)
Summary
Summary
Summary Epilogue:
what next?
List of Figures
List of Tables
List of Listings
Preface
Today, functional programming (FP) is no longer brooding in the research departments of
universities; it has become an important and exciting part of mainstream programming. The
majority of the languages and frameworks created in the last decade are functional, leading some
to predict that the future of programming is functional. Meanwhile, popular object-oriented
languages like C# and Java see the introduction of more functional features with every new
release, enabling a multiparadigm programming style.
And yet, adoption in the C# community has been slow. Why is this so? One reason, I believe, is
the lack of good literature:
Most FP literature is written in and for functional languages, especially Haskell. For
developers with a background in OOP, this poses a programming-language barrier to
learning the concepts. Even though many of the concepts apply to a multiparadigm
language like C#, learning a new paradigm and a new language at once is a tall order.
Even more importantly, most of the books in the literature tend to illustrate functional
techniques and concepts with examples from the domains of mathematics or computer
science. For the majority of programmers who work on line-of-business (LOB)
applications day in and day out, this creates a domain gap and leaves them wondering how
relevant these techniques may be for real-world applications.
These shortcomings posed major stumbling blocks in my own path to learning FP. After tossing
aside the n-th book that explained something known as currying by showing how the add
function can be curried with the number 3, creating a function that can add 3 to any number (can
you think of any application where this would be even remotely useful?), I decided to pursue my
own research path. This involved learning half a dozen functional languages (some better than
others), and seeing which concepts from FP could be effectively applied in C# and in the kind of
applications most developers are paid to write, and it culminated in the writing of this book.
This book bridges the language gap for C# developers by showing how you can leverage
functional techniques in this language. It also bridges the domain gap by showing how these
techniques can be applied to typical business scenarios. I take a pragmatic approach and cover
functional techniques to the extent that they’re useful in a typical LOB application scenario, and
dispense with most of the theory behind FP.
Ultimately, you should care about FP because it gives you the following:
Power— This simply means that you can get more done with less code. FP raises the level
of abstraction, allowing you to write high-level code while freeing you from low-level
technicalities that add complexity but no value.
Safety— This is especially true when dealing with concurrency. A program written in the
imperative style may work well in a single-threaded implementation but cause all sorts of
bugs when concurrency comes in. Functional code offers much better guarantees in
concurrent scenarios, so it’s only natural that we’re seeing a surge of interest in FP in the
era of multicore processors.
Clarity— We spend more time maintaining and consuming existing code than writing new
code, so it’s important that our code be clear and intention-revealing. As you learn to think
functionally, achieving this clarity will become more natural.
If you’ve been programming in an object-oriented style for some time, it may take a bit of effort
and willingness to experiment before the concepts in this book come to fruition. To make sure
learning FP is an enjoyable and rewarding process, I have two recommendations:
Be patient— You may have to read some sections more than once. You may put the book
down for a few weeks and find that when you pick it up again, something that seemed
obscure suddenly starts to make sense.
Experiment in code— You won’t learn unless you get your hands dirty. The book
provides many examples and exercises, and many of the code snippets can be tested in the
REPL.
Your colleagues may be less eager to explore than you. Expect them to protest your adoption of
this new style and to look perplexed at your code and say things like, “why not just do x?”
(where x is boring, obsolete, and usually harmful). Don’t discuss. Just sit back and watch them
eventually turn around and use your techniques to solve issues they run into again and again.
Acknowledgments
I’d like to thank Paul Louth, who not only provided inspiration through his LanguageExt library—
from which I borrowed many good ideas—but who also graciously reviewed the book at various
stages.
Manning’s thorough editorial process ensured that the quality of this book is infinitely better than
if I had been left to my own means. For this, I’d like to thank the team that collaborated on the
book, including Mike Stephens, development editor Marina Michaels, technical editor Joel
Kotarski, technical proofreader Jürgen Hoetzel, and copyeditor Andy Carroll.
Special thanks to Daniel Marbach and Tamir Dresher for their technical insights, as well as to all
those who took part in the peer reviews, including Alex Basile, Aurélien Gounot, Blair Leduc,
Chris Frank, Daniel Marbach, Devon Burriss, Gonzalo Barba López, Guy Smith, Kofi Sarfo,
Pauli Sutelainen, Russell Day, Tate Antrim, and Wayne Mather.
Thanks to Scott Wlaschin for sharing his articles at http://fsharpforfunandprofit.com, and to the
many other members of the FP community who share their knowledge and enthusiasm through
articles, blogs, and open source.
About this Book
This book aims to show how you can leverage functional techniques in C# to write code that is
concise, elegant, robust, and maintainable.
Who should read this book
This book is for an ambitious breed of developer. You know the C# language and the .NET
framework. You have experience developing real-world applications and are familiar with OOP
concepts, patterns, and best practices. Yet, you’re looking to expand your arsenal by learning
functional techniques so that you can make the most out of C# as a multiparadigm language.
If you’re trying or planning to learn a functional language, this book will also be hugely
valuable, because you’ll learn how to think functionally in a language you’re familiar with.
Changing the way you think is the hard part; once that’s achieved, learning the syntax of any
particular language will be relatively easy.
How this book is organized
The book consists of 15 chapters, divided into 3 parts:
Part 1 covers the basic techniques and principles of functional programming. We’ll start by
looking at what functional programming is and how C# supports programming in a
functional style. We’ll then look at the power of higher-order functions, function purity
and its relation to testability, the design of types and function signatures, and how simple
functions can be composed into complex programs. By the end of part 1, you’ll have a
good feel for what a program written in a functional style looks like and for the benefits
that this style has to offer.
With these basic concepts covered, we’ll pick up some speed in part 2 and move on to
wider-reaching concerns, such as functional error handling, modularizing and composing
an application, and the functional approach to understanding state and representing change.
By the end of part 2, you’ll have acquired a set of tools enabling you to effectively tackle
many programming tasks using a functional approach.
Part 3 will tackle more advanced topics, including lazy evaluation, stateful computations,
asynchrony, data streams, and concurrency. Each chapter in part 3 introduces important
techniques that have the potential to completely change the way you write and think about
software.
You’ll find a more detailed breakdown of the topics in each chapter, and a representation of what
chapters are required before reading any particular chapter, on the inside front cover page.
The book aims to stay true to real-world scenarios. To do this, many examples deal with practical
tasks such as reading configuration, connecting to a database, validating HTTP requests, and so
on—things you may already know how to do, but you’ll see them with the fresh perspective of
functional thinking.
Throughout the book, I use a long-running example to illustrate how FP can help when writing
LOB applications. For this, I’ve chosen an online banking application for the fictitious Bank of
Codeland (BOC)—naff, I know, but at least it has the obligatory three-letter acronym. Because
most people have access to an online banking facility, it should be easy to imagine the required
functionality and plain to see how the problems discussed are relevant to real-world applications.
I also use scenarios to illustrate how to solve typical programming problems in a functional style.
The constant back and forth between practical examples and FP concepts will hopefully help
bridge the gap between theory and practice—something I found wanting in the existing
literature, as I mentioned.
A language like C# may have functional features, but to fully leverage these you’ll often use
libraries that facilitate common tasks. Microsoft has provided several libraries that facilitate
programming in a functional style, including these:
System.Linq—Yes, in case you didn’t know, it’s a functional library! I assume you’re
familiar with it, given that it’s such an important part of .NET.
System.Collections.Immutable—This is a library of immutable collections, which we’ll start
using in chapter 9.
System.Reactive—This is an implementation of the Reactive Extensions for .NET, allowing
you to work with data streams, which we’ll discuss in chapter 14.
This still leaves out plenty of other important types and functions that are staples of FP. As a
result, several independent developers have written libraries to fill those gaps. To date, the most
complete of these is LanguageExt, a library written by Paul Louth to improve the C# developer’s
experience when coding functionally.[1]
1
In the book, I don’t use LanguageExt directly; instead, I’ll show you how I developed my own
library of functional utilities, called LaYumba.Functional, even though it largely overlaps with
LanguageExt. This is pedagogically more useful, for several reasons:
You can execute many of the shorter snippets of code in a REPL, thereby gaining hands-on
practice with immediate feedback. The more extended examples are available for download at
https://github.com/la-yumba/functional-csharp-code, along with the exercises’ setup and
solutions.
Code listings in the book focus on the topic being discussed, and therefore may omit
namespaces, using statements, trivial constructors, or sections of code that appeared in a previous
listing and remain unchanged. If you’d like to see the full, compiling version of a listing, you’ll
find it in the code repository: https://github.com/la-yumba/functional-csharp-code.
Book forum
Purchase of Functional Programming in C# includes free access to a private web forum run by
Manning Publications where you can make comments about the book, ask technical questions,
and receive help from the author and from other users. To access the forum, go to
https://forums.manning.com/forums/functional-programming-in-c-sharp. You can also learn
more about Manning’s forums and the rules of conduct at
https://forums.manning.com/forums/about.
Chapter 1 starts by looking at what functional programming is, and how C# supports
programming in a functional style. It then delves deeper into higher-order functions, a
fundamental technique of FP.
Chapter 2 explains what pure functions are, why purity has important implications for a
function’s testability, and why pure functions lend themselves well to parallelization and other
optimizations.
Chapter 3 deals with principles for designing types and function signatures—things you thought
you knew but that receive a breath of fresh air when looked at from a functional perspective.
Chapter 4 introduces some of the core functions of FP: Map, Bind, ForEach, and Where (filter). These
functions provide the basic tools for interacting with the most common data structures in FP.
Chapter 5 shows how functions can be chained into pipelines that capture the workflows of your
program. It then widens the scope to developing a whole use case in a functional style.
By the end of part 1, you’ll have a good feel for what a program written in a functional style
looks like, and you’ll understand the benefits that this style has to offer.
Another random document with
no related content on Scribd:
CHAPTER TWENTY
“THAT CAT AIN’T HUMAN!”
Monty rode rather anxiously into Johnnywater Cañon, determined
to take whatever means he found necessary to persuade Gary to
return to Los Angeles and “make it up with his girl.” With three
weeks’ wages in his pocket Monty felt sufficiently affluent to buy the
pigs and chickens if Gary used them for a point in his argument
against going.
Monty had spent a lot of time during those three weeks in mulling
over in his mind the peculiar chain of circumstances that had
dragged Gary to Johnnywater. What bond it was that held him there,
Monty would have given much to know. He was sure that Gary
disliked the place, and that he hated to stay there alone. It seemed
unreasonable that any normal young man would punish himself like
that from sheer stubbornness; yet Gary would have had Monty
believe that he was staying to spite Patricia.
Monty did not believe it. Gary had shown himself to be too
intelligent, too level-headed and safely humorous in his viewpoints to
harbor that peculiar form of egotism. Monty was shrewd enough to
recognize the fact that “cutting off the nose to spite the face” is a
sport indulged in only by weak natures who own an exaggerated
ego. Wherefore, Gary failed to convince him that he was of that type
of individual.
At the same time, he could think of no other reason that could
possibly hold a man like Gary Marshall at Johnnywater. Monty had a
good memory for details. Certain trivial incidents he remembered
vividly: Gary’s stealthy approach around the corner of the cabin with
the upraised pitchfork in his hands; Gary’s forced gayety afterwards,
and the strained look in his eyes—the lines beside the mouth; Gary’s
reluctance to speak of the uncanny, nameless something that clung
to Johnnywater Cañon; the incomprehensible behavior of the spotted
cat. And always Monty brought up short with a question which he
asked himself but could not answer.
Why had Gary Marshall described Steven Carson—who had
dropped from sight of mortal eyes five years and more ago?—why
had Gary described Steve Carson and asked if that description fitted
Waddell?
“Gary never saw Steve Carson—not when he was alive, anyway.
He says the Indians never told him how Steve looked. I reckon he
really thought Waddell was that kind uh lookin’ man. But how in
thunder did he get the idea?” Monty frequently found himself
mentally asking that question, but he never attempted to put an
answer into words. He couldn’t. He didn’t know the answer.
So here he was, peering anxiously at the cabin squatted between
the two great piñon trees in the grove and hoping that Gary was still
all right. He had consciously put aside an incipient dread of James
Blaine Hawkins and his possible vengefulness toward Gary. Monty
told himself that there was no use in crossing that bridge until he
came to it. He had come over for the express purpose of offering to
take the Walking X cattle on shares and look after them with his own.
He would manage somehow to take charge of the pigs and chickens
as well. He decided that he could kill the pigs and pack the meat
over on his horse. And he could carry the chickens on a pack horse
in a couple of crates. There would be nothing then to give Gary any
excuse for staying.
Remembering how he had startled Gary before with calling, Monty
did not dismount at the cabin. Instead, he rode close to the front
window, leaned and peered in like an Indian; and finding the cabin
empty, he went on through the grove to the corral. Jazz was there,
standing hip-shot in a shady corner next the creek, his head nodding
jerkily while he dozed. Monty’s horse whinnied a greeting and Jazz
awoke with a start and came trotting across the corral to slide his
nose over the top rail nearest them.
Monty rode on past the potato patch and the alfalfa meadow
where a second crop was already growing apace. There was no sign
of Gary, and Monty rode on to the very head of the cañon and back
to the cabin.
A vague uneasiness seized Monty in spite of his efforts to throw it
off. Gary should be somewhere in the cañon, since he would not
leave it afoot, not while he had a horse doing nothing in the corral. Of
course, if anything were wrong with Jazz——Monty turned and rode
back to the corral, where he dismounted by the gate. He went in and
walked up to Jazz, and examined him with the practiced palms of the
expert horseman. He slapped Jazz on the rump and shooed him
around the corral at a lope.
“There ain’t a thing in the world the matter with you,” he told the
horse, after a watchful minute or two. Then he rolled a cigarette,
lighted and smoked it while he waited and meditated upon the
probable whereabouts of Gary.
He went out into the open and studied the steep bluff sides, foot
by foot. The entire width of the cañon was no more than a long rifle-
shot. If Gary were climbing anywhere along its sides, Monty would
be able to see him. But there was no sign of movement anywhere,
though he took half an hour for the examination.
He returned to the cabin, leaving his horse in the corral with
saddle and bridle off and a forkful of hay under his eager nose. He
shouted Gary’s name.
“Hey, Gary! Oh-h-h, Gary!” he called, over and over, careful to
enunciate the words.
From high up on the bluff somewhere the Voice answered him
mockingly, shouting again and again a monotonous, eerie call. There
was no other sound for a time, and Monty went into the cabin to see
if he could find there some clue to Gary’s absence.
Little things bear a message plain as print to those dwellers of the
wilderness who depend much upon their eyes and their ears. The
cabin told Monty with absolute certainty that Gary had not planned
an absence of more than a few hours at most. Nor had he left in any
great haste. He had been gone, Monty judged, since breakfast. Of
the cooked food set away in the cupboard, two pancakes lay on top
of a plate containing three slices of fried bacon. To Monty that meant
breakfast cleared away and no later meal prepared. He looked at his
watch. He had taken an early start from Kawich, and it was now two
o’clock.
He lifted the lid of the stove and reached in, feeling the ashes.
There had been no fire since morning; he was sure of that. He stood
in the middle of the room and studied the whole interior
questioningly. Gary’s good clothes—which were not nearly so good
as they had been when Monty first saw him—hung against the wall
farthest from the stove, the coat neatly spread over a makeshift
hanger. Gary’s good hat was in the cupboard nailed to the wall. A
corner of his suit case protruded from under the bunk. Gary was in
the rough clothes he had gleaned from Waddell’s leavings.
Monty could not find any canteen, but that told him nothing at all.
He could not remember whether Waddell had canteens or not. The
vague uneasiness which he had at first smothered under his natural
optimism grew to a definite anxiety. He knew the ways of the desert.
And he could think of no plausible reason why Gary should have left
the cañon afoot.
He went out and began looking for tracks. The dry soil still held
the imprint of automobile tires, but it was impossible to tell just how
long ago they had been made. Several days, at least, he judged
after a careful inspection. He heard a noise in the bushes across the
little creek and turned that way expectantly.
The spotted cat came out of the brush, jumped the tiny stream
and approached him, meowing dolefully. Monty stood stock still,
watching her advance. She came directly toward him, her tail
drooping and waving nervously from side to side. She looked straight
up into his face and yowled four or five times without stopping.
“Get out, damn yuh!” cried Monty and motioned threateningly with
his foot. “Yuh can’t stand there and yowl at me—I got enough on my
mind right now.”
The mottled cat ducked and started back to the creek, stopping
now and then to look over her shoulder and yowl at Monty. Monty
picked up a pebble and shied it after her. The cat gave a final squall
and ran into a clump of bushes a few yards up-stream from where
Monty had first seen her.
“That damned cat ain’t human!” Monty ejaculated uncomfortably.
“That’s the way she yowled around when Steve Carson——” He
lifted his shoulders impatiently at the thought.
After a minute or two spent in resisting the impulse, Monty yielded
and started out to see where the cat had gone. Beyond the clump of
bushes lay an open space along the bank of the creek. On the
farther side he saw the mottled cat picking her way through weeds
and small bushes, still going up the creek and yowling mournfully as
she went. Monty walked slowly after her. He noticed, while he was
crossing the open space, a man’s footprints going that way and
another set coming back. The soil was too loose to hold a clear
imprint, so that Monty could not tell whose tracks they were; though
he believed them to have been made by Gary.
The cat looked back and yowled at Monty, then went on. At a
point nearly opposite the potato patch the cat stopped near a bushy
little juniper tree that stood by itself where the creek bank rounded
up to a tiny knoll. As Monty neared the spot the cat leaped behind
the juniper and disappeared.
Monty went closer, stopped with a jerk and stood staring. He felt
his knees quiver with a distinct tendency to buckle under him. The
blood seeped slowly away from his face, leaving it sallow under the
tan.
Monty was standing at the very edge of a narrow mound of earth
that still bore the marks of a shovel where the mound had been
smoothed and patted into symmetrical form. A grave, the length of a
man.
Here again were the blurred footprints in the loose soil. Who had
made them, what lay buried beneath that narrow ridge of heaped
sand, Monty shrank from conjecturing.
With an involuntary movement, of which Monty was wholly
unconscious, his right hand went up to his hat brim. He stood there
for a space without moving. Then he turned and almost ran to the
corral. It was not until he reached to open the gate that Monty
discovered his hat in his hand.
He was thinking swiftly now, holding his thoughts rigidly to the
details of what he must do. The name Hawkins obtruded itself
frequently upon his mind, but he pushed the thought of Hawkins from
him. Beyond the details of his own part, which he knew he must play
unfalteringly from now on, he would not think—he could not bear to
think. He saddled Jazz, mounted and led his own horse down to the
cabin. Working swiftly, he packed a few blankets, food for three days
and his own refilled canteens upon the led horse.
Then with a last shrinking glance around the cañon walls, he
mounted Jazz. He remembered then something that he must do,
something that Gary would wish to have him do. He rode back to the
stone pen and opened the gate so that the pigs could run free and
look after themselves.
He remounted, then half-turned in the saddle and took up the
slack in the lead rope, got the led horse straightened out behind him
and kicked Jazz into a trot. In his mental stress he loped the horses
all the way down to the cañon’s mouth. And then, striking into the
dim trail, he went racking away over the small ridges and into the
hollows, heading straight for the road most likely to be traveled in
this big, empty land; the road that stretched its long, long miles
between Goldfield and Las Vegas.
CHAPTER TWENTY-ONE
GARY FOLLOWS THE PINTO CAT
Gary had prospected pretty thoroughly the whole cañon, following
the theory that some one—he felt that it was probably Steve Carson
—had carried that rich, gold-bearing rock down to the cabin. Waddell
had left neither chemicals nor appliances by which he could test any
of the mineralized rock he found; but Gary was looking for one
particular kind, the porphyry that carried free gold.
Greater than the loneliness, stronger than his dread of the cañon
and the cabin, was his desire to find more of that gold-bearing rock.
It would not take much of it to make Pat’s investment in Johnnywater
more than profitable. He even climbed to the top of the butte—a
heart-breaking effort accomplished at the risk of his neck on the
sheer wall of the rim rock. There was no means of knowing just
where that porphyry had come from. In some prehistoric eruption it
might have been thrown for miles, though Gary did not believe that it
had been. The top of the bluff gave no clue whatever. Malapi
bowlders strewed much of the surface with outcroppings of country
rock. Certainly there was no sign of mineral up there. He tramped
the butte for miles, however, and spent two days in doing it. Then,
satisfied that the porphyry must be somewhere in the cañon, he
renewed his search on the slope.
Prospecting here was quite as difficult, because so much of the
upper slopes was covered with an overburden of the malapi that
formed the rim rock. Portions of the rim would break and slide when
the storms beat upon it. Considerable areas of loose rock had
formed during the centuries of wear and tear, and if there had been
mineral outcroppings they were as effectually hidden as if they had
never come to the surface at all. But a strain of persistence which
Gary had inherited from pioneering forebears held him somewhat
doggedly to the search.
He reasoned that he had more time than he knew what to do with,
and if a fortune were hidden away in this cañon, it would be
inexcusable for him to mope through the days without making any
systematic effort to find it. Patricia deserved the best fortune the
world had to bestow. To find one for her would, he told himself
whimsically, wipe out the stain of owning a profile and a natural
marcel wave over his temples. Pat might possibly forgive even his
painted eyebrows and painted lashes and painted lips, if he found
her a gold mine.
So he tramped and scrambled and climbed from one end of the
cañon walls to the other, and would not hint to Monty Girard what it
was that held him in Johnnywater Cañon. He would not even put his
hopes on paper in the long, lonely evenings when he wrote to
Patricia. After the jibing letter concerning the millions she might have
if she owned a mine as rich as the rock he had found behind the
cabin, Gary had not put his search into words even when he talked
to Faith.
He found himself thinking more and more about Steve Carson.
The weak-souled Waddell he had come practically to ignore.
Waddell had left no impress upon the cañon, at least, so far as Gary
was concerned. And that in spite of the fact that he was walking
about in Waddell’s boots and trousers, wearing Waddell’s hat,
tending Waddell’s pigs. Walking in Waddell’s boots, Gary wondered
about Steve Carson, speculated upon his life and his hopes and the
things he had put away in his past when he came to Johnnywater to
live alone, wholly apart from his fellows. Steve Carson’s hands had
built the cabin between the two piñons. Steve Carson—Gary did not
attempt any explanation of why he knew it was so—had brought the
gold-bearing rock to the cabin. A prospector of sorts, he must have
been, to have found gold-bearing rock in that cañon.
It was during the forenoon after Gary had returned from Kawich
that he obeyed a sudden, inexplicable impulse to follow Faith, the
mottled cat.
Ever since Gary had come to Johnnywater he had seen Faith go
off across the creek after breakfast. Usually she returned in the
course of three or four hours, and frequently she brought some small
rodent or a bird home with her. Gary had been faintly amused by the
pinto cat’s regular hours and settled habits of living. He used to
compliment her upon her decorous behavior, stroking her back while
she purred on his knee, her paws tucked snugly close to her body.
On this morning Gary rose abruptly from the doorstep, and,
bareheaded, he followed Faith across the creek and up the bluff. It
was hot climbing, but Gary did not think about the heat. Indeed, he
was not consciously thinking of anything much. He was simply
following Faith up the bluff, because he had got up from the doorstep
to follow Faith.
Faith climbed up and up quite as if she knew exactly where she
was going. Gary, stopping once on a bowlder to breathe for a minute
after an unusually stiff bit of climbing, saw the cat look up in the
queer way she had of doing. In a minute she went on and Gary
followed.
It began to look as if Faith meant to climb to the top of the butte.
She made her way around the lower edge of a slide, went out of
sight into a narrow gulch which Gary, with all his prospecting had
never noticed before—or at least had never entered—and
reappeared farther up, just under the rim rock where many slides
had evidently had their birth. For the first time since he had left the
cabin, the cat looked back at Gary, gave an amiable mew and waited
a minute before she started on.
Gary hesitated. He was thirsty, and the rapid climb was beginning
to tell on him. He looked back down the bluff to the cool green of the
grove, and for the first time wondered why he had been such a fool
as to follow a cat away up here on a hunting trip in which he could
not possibly take any active interest or part. He told himself what a
fool he was and said he must be getting goofy himself. But when he
moved it was upward, after the cat.
He brought up at the foot of a high ledge seamed and cracked as
one would never suspect, looking up from below. It was up here
somewhere that the Voice always seemed to be located. He stopped
and listened, but the whole cañon lay in a somnolent calm under the
mounting sun. It looked as if nothing could disturb it; as if there never
could be a Voice other than the everyday voices of men. While he
stood there wiping his forehead and panting with the heat and the
labor of climbing, the red rooster down in the grove began to crow
lustily. The sound came faintly up to Gary, linking him lightly to
commonplace affairs.
A little distance away the cat had curled herself down in a tiny
hollow at the edge of the slide. Gary made his way over to her. She
opened one eye and regarded him sleepily, gave a lazy purr or two
and settled herself again more comfortably. Gary saw, from certain
small scratchings in the gravel, that the pinto cat had made this little
nest for herself. She had not been hunting at all. She had come to a
spot with which she was very familiar.
CHAPTER TWENTY-TWO
THE PAT CONNOLLY MINE
Gary decided offhand that he had been neatly sold. He sat down
on the loose rubble near Faith and made himself a smoke. The
grove and the cabin were hidden from him by the narrow little ridge
that looked perfectly smooth from the cañon bottom. But the rest of
the cañon—the corral, the potato patch, the alfalfa—lay blocked out
in miniature far below him. He stared down upon the peaceful picture
it made and wondered why he had climbed all the way up here just
following the pinto cat. For the matter of that, his following the cat
was not half so purposeless as the cat’s coming had been.
He looked down at her curled asleep in her little hollow. It struck
him that this must have been her destination each time she crossed
the creek and started up the bluff. But why should the cat come
away up here every day? Gary did not attempt to explain the
vagaries of a cat so eccentric as Faith had proved herself to be. He
wondered idly if he were becoming eccentric also, just from constant
association with Faith.
He laughed a little to himself and picked up a piece of malapi rock;
balanced it in his hand while he thought of other things, and tossed it
down the slide. It landed ten feet below him and began rolling farther,
carrying with it a small avalanche of loose rocks. Gary watched the
slide with languid interest. Even so small a thing could make a tiny
ripple in the dead calm of the cañon that day.
The slide started by that one rock spread farther. Other rocks
loosened and went rolling down the bluff, and Gary’s eyes followed
them and went higher, watching to see where next a rock would slip
away from the mass and go rolling down. It seemed to him that the
whole slide might be easily set in motion with no more than a kick or
two at the top. He got up and began to experiment, kicking a rock
loose here and there. There was no danger to himself, since he
stood at the top of the slide. As for Faith, she had sprung up in a
furry arch at the first slithering clatter and was now viewing the scene
with extreme disfavor from the secure vantage point of a shelf on the
ledge above Gary.
In a very few minutes Gary had set the whole surface of the slide
in motion. The noise it made pleased him immensely. It served to
break that waiting silence in the cañon. When the rocks ceased
rolling, he started others. Finally he found himself standing upon firm
ground again, with an outcropping of gray quartz just below him. His
eyes fixed themselves upon the quartz in a steady stare before he
dug heels into the slope and edged down to it.
With a malapi rock bigger than his two fists he hammered off a
piece of quartz and held it in the shade of his body while he
examined it closely. He turned it this way and that, fearful of
deceiving himself by the very strength of his desire. But all the while
he knew what were those little yellow specks that gleamed in the
shade.
He knelt and pounded off other pieces of the quartz and
compared them anxiously with the first. They were all identical in
character: steel gray, with here and there the specks of gold in the
gray, and the chocolate brown streaks and splotches of hematite—
the “red oxide” iron which runs as high as seventy per cent. iron.
Hematite and free gold in gray quartz——
“A prettier combination for free gold I couldn’t have made to
order!” he whispered, almost as if he were praying. “It’s good enough
for my girl’s ‘million-dollar mine’—though they do get rich off a piece
of gold float in the movies!” He began to laugh nervously. A weaker-
souled man would probably have wept instead.
With the side of his foot he tore away the rubble from the quartz
outcropping. There, just where he had been kneeling, he discovered
a narrow vein of the bird’s-eye porphyry such as he had found at the
cabin. Here, then, lay the object of all his tiresome prospecting. So
far as he could judge, with only his hands and feet for digging, the
vein averaged about eight inches in width. Whether the porphyry
formed a wall for the quartz he could not tell at the surface; but he
hoped fervently that it did. With hematite, gray quartz and bird’s-eye
porphyry he would have the ideal combination for a rich, permanent
gold mine. And Pat, he reflected breathlessly, might really have her
millions after all.
He picked up what he believed to be average samples of the vein
and started back down the bluff, his imagination building air castles,
mostly for Patricia. If he dramatized the event and cast himself for
the leading man playing opposite Patricia, who was the star, surely
he had earned the right to paint rose tints across the veil that hid his
future and hers.
He had forgotten all about the cat; but when he reached the cabin,
there she was at his heels looking extremely self-satisfied and
waving her tail with a gentle air of importance. Gary laid his ore
samples on the table and stood with his hands on his hips, looking
down at Faith with a peculiar expression in his eyes. Suddenly he
smiled endearingly at the cat, stooped and picked her up, holding
her by his two hands so that he could look into her eyes.
“Doggone you, Faith, I wish to heck you could talk! I wouldn’t put it
past you to think like humans. I’ll bet you’ve been trying all along to
show me that outcropping. And I thought you were hunting mice and
birds and gophers just like a plain, ordinary cat! You can’t tell me—
you knew all about that gold! I’ll bet you’ve got a name all picked out
for the mine, too. But it won’t go, I’ll tell a meddlesome world. That is,
unless you’ve decided it ought to be called ‘The Pat Connolly.’
Because that’s the way it’s going on record, if Handsome Gary has
anything to say about it—and I rather think he has!”
Faith blinked at him and mewed understandingly. Gary wooled her
a bit and put her down, considerately smoothing down the fur he had
roughed. Faith was a forgiving cat, and she immediately began
purring under his fingers. After that she tagged him indefatigably
while he got mortar, pestle and pan, and carried them down to a
shady spot beside the creek.
Gary’s glance strayed often to the bluff while he broke bits off
each sample of quartz and dropped them into the iron mortar. Then,
with the mortar held firmly between his knees, Gary picked up the
eight-inch length of iron with the round knob on the end and began to
pulverize the ore. For a full quarter of an hour the quiet air of the
grove throbbed to the steady pung, pung, pung, of the iron pestle
striking upon rock particles in the deep iron bowl.
About twice in every minute, Gary would stop, dip thumb and
finger into the mortar, and bring up a pinch of pulverized rock at
which he would squint with the wholly unconscious eagerness of a
small boy. Naturally, since he was not flattening a nugget of solid
gold in the mortar, he failed to see anything except once when he
caught an unmistakable yellow gleam from a speck of gold almost
half the size of a small pinhead.
He gloated over that speck for a full minute before he shook it
carefully back into the mortar. And then you should have heard him
pound!
He was all aquiver with hope and eager expectancy when at last
he poured the pulverized quartz into the gold pan and went digging
his heels down the bank to the water. Faith came forward and stood
upon a dry rock, mewing and purring by turns, and waving her tail
encouragingly while she watched him.
Those who plod along the beaten trail toward commercial success
can scarcely apprehend the thrill of winning from nature herself the
symbol that promises fulfillment of hope and dreams coming true.
The ardency of Gary’s desire was measurable only by the depth of
his love for Patricia. For himself he had a man’s normal hunger for
achievement. To discover a gold mine here in Johnnywater Cañon,
to develop it in secret to the point where he could command what
capital he needed for the making of a real mine, that in itself seemed
to Gary a goal worth striving for. To fill Patricia’s hands with virgin
gold which he had found for her, there spoke the primitive desire of
man since the world was young; to bring the spoils of war or the
chase and lay them, proud offering of love, at the feet of his Woman.
Gary turned and tilted the pan, tenderly as a young mother
cradles her first-born. He dipped and rocked and spilled the water
carefully over the rim; dipped and rocked and tilted again. The three
deep creases stood between his straight, dark eyebrows, but now
they betokened eager concentration upon his work. At last, he
poured clear water from the pan carefully, almost drop by drop. He
tilted the pan slowly in the sunlight and bent his head, peering
sharply into the pan. His heart seemed to be beating in his throat
when he saw the trail of tiny yellow particles following sluggishly the
spoonful of black sand when he tilted the pan.
“I’ve got it, Steve,” he exclaimed, looking up over his shoulder. He
caught his breath in the sudden realization that he was looking into
the empty sunlight. Absorbed as he had been in the gold, the felt
presence of Steve Carson looking over his shoulder had seemed
perfectly natural and altogether real.
The momentary shock sobered him. But the old dread of that felt
presence no longer assailed him as something he must combat by
feigning unconsciousness. The unreasoning impression that Steve
Carson—the mind of him—was there just behind his shoulder,
watching and sharing in his delight, persisted nevertheless. Gary
caught himself wondering if the thing was really only a prank of his
imagination. Feeling a bit foolish, but choosing to indulge the
whimsy, he stood up and turned deliberately, the pan held out before
him.
“Steve Carson, if dead people go on living and thinking, and if you
really are hanging around just out of sight but watching the game,
I’m here to say that I hope you’re glad I found this vein. And I want to
tell you right now that if there’s any money to be made out of it, it’s
going to the finest, squarest little girl in the world. So if there is such
a thing as a spirit, just take it from me everything’s going to be on the
square.”
He carried the pan up to the cabin and carefully rinsed the gold
down into a jelly glass. He made no apology to himself for the little
speech to a man dead and gone these five years. Having made
himself as clear on the subject as was diplomatic—supposing Steve
Carson’s spirit had been present and could hear—he felt a certain
relief and could lay the subject aside and devote himself to the
fascination of hunting the gold out of the hills where it had lain buried
for ages.
It occurred to him that he might find some particularly rich
specimens, mortar them by hand and pan them for Patricia. A
wedding ring made from the first gold taken and panned by hand—
the hand of Gary Marshall—from “The Pat Connolly” mine, appealed
to him irresistibly. Before he had mortared a lump of porphyry the
size of a pigeon’s egg, Gary had resolved to pan enough gold for
that very purpose. He pictured himself pulling the ring from his vest
pocket while the minister waited. He experienced a prophetic thrill of
ecstasy when he slipped the ring upon Patricia’s finger. The
dreamed sentence, “I now pronounce you man and wife,” intoned by
an imaginary minister, thrilled him to the soul.
Pung, pung, pung! It wouldn’t take so very long, if he mortared
rock evenings, say, instead of killing time minute by minute playing
solitaire with the deck of cards Waddell had thumbed before him.
Pung, pung, pung! He could mortar the quartz in the evenings and
pan it in the morning before he went to work. Pung, pung, pung,
pung! He would hunt up a cow’s horn and fix it as he had seen old
prospectors do, so that he could blow the sand from the panned gold
and carry it unmixed to the jeweler. Pung, pung! The porphyry
sample was fine as corn meal under the miniature stamp-mill of
Gary’s pounding.
He was mighty careful of that handful of pulp. He even dipped the
mortar half full of water and sloshed it round and round, pouring it
afterward into the pan to rinse out what gold may have stuck to the
iron. His finger tips stirred the wet mass caressingly in the pan,
muddying the water with the waste matter and pouring that out
before he squatted on his heels at the edge of the stream.
The result was gratifying in the extreme. Granting that the values
were inclined to “jump” from quartz to porphyry and back again to the
quartz, he would still lose none of the gold. He tried to be very
conservative in estimating the probable value of the vein. He knew
that, granting quartz and porphyry were in place from the surface
downward, the values should increase with depth. It would take
some digging, however, to determine that point. He was glad that
Patricia knew nothing at all about it. If there were to be
disappointment later on, he wanted to bear it alone. The joys of
success he was perfectly willing to share; but not the sickening
certitude of failure. He judged that the outcropping would run several
hundred dollars to the ton, provided his panned samples had run a
fair average of the vein.
Material for air castles aplenty, that! Gary was afraid to believe it.
He kept warning himself headily that the world would be peopled
entirely with multimillionaires if every man’s dream of wealth came
true and every man’s hopes were realized.
“Ninety-nine per cent. of all mineral prospects are failures, Faith,”
he told the spotted cat admonishingly. “We may get the raspberry yet
on this proposition. I’m just waiting to see whether you’re a mascot
or a jinx. I wish to heck you were a dog—I’d make you get busy and
help dig!”
CHAPTER TWENTY-THREE
GARY FINDS THE VOICE—AND SOMETHING
ELSE
“Here’s where Handsome Gary raises a crop of callouses big as
birds’ eggs in his mad pursuit of the fickle jade, Fortune. Come on,
Faith, doggone you; I want you handy in case this gold thing is a
fluke.”
Gary had remembered that eating is considered necessary to the
preservation of life and had delayed his further investigation of the
outcropping until he had scrambled together some sort of a meal. He
had bolted food as if he must hurry to catch a train that was already
whistling a warning. Now he took down a canteen from behind the
door, shouldered an old pick and shovel he had found in the shed,
and started back up the bluff, stopping just long enough to fill the
canteen at the creek as he passed.
Loaded with canteen and tools, the climb was a heart-breaking
one. The spotted cat led the way, going as straight as possible
toward the tiny ridge behind which lay the outcropping. At the top,
Gary decided that hereafter he would bring a lunch and spend the
day up there, thus saving a valuable hour or two and a good deal of
energy. Energy, he realized, would be needed in unlimited quantities
if he did much development work alone.
By hard labor he managed to clear away the rubble of the slide
and uncover the vein for a distance of several feet before dusk
began to fill the cañon. He carried down with him the richest pieces
of rock that he could find, and that night he worked with mortar and
pestle until his arms ached with the unaccustomed exercise.
Several times that evening he was pulled away from his air
castles by the peculiar sensation of some one standing very close to
him. It was not the first time he had experienced the sensation, but
never before had the impression brought him a comforting sense of
friendly companionship. It struck him suddenly that he must be
growing used to the idea, and that Johnnywater Cañon was not at all
likely to “get” him as it had got Waddell. He had not heard the Voice
all day, but he believed that he could now listen to it with perfect
equanimity.
He had just one worry that evening; rather, he had one difficult
problem to solve. In order to work in that quartz, dynamite was
absolutely necessary. Unless he could find some on the place, it
began to look very much as if he would not be able to do much
unless he could get some brought out to him from town.
The result of his cogitations that evening was a belief that Steve
Carson must have had dynamite, caps and fuse on hand. Men living
out in a country known to produce minerals of one sort and another
usually were supplied with explosives. Even if they never did any
mining, they might want to blow a bowlder out of the way now and
then. He had never seen any powder about the place; but on the
other hand, he had not looked for any.
The next morning he panned the pulped rock immediately after
breakfast and was overjoyed at the amount of gold he gleaned from
the pint or so of pulp. At that rate, he told himself gleefully, the
wedding ring would not need to wait very long. After that he went
hunting dynamite in the storehouse and shed. He was lucky enough
to find a couple of dozen sticks of powder and some caps and fuse
wrapped in a gunny sack and hung from the ridgepole of the shed.
The dynamite did not look so very old, and he guessed that it had
been brought there by Waddell. This seemed to him an amazing bit
of good luck, and he shouldered the stuff and went off up the bluff
with an extra canteen and his lunch, whistling in an exuberance of
good humor with the world. Faith, of course, went with him and
curled herself in her little hollow just under the frowning malapi
ledge.
Gary worked for three days, following the quartz and porphyry
down at an incline of forty-five degrees. The vein held true to form,
and the samples he panned each morning never failed to show a
drag of gold after the concentrate. It was killing work for a man
unused to pick and shovel. In the afternoon of the third day even
Gary’s driving energy began to slow down. He had learned how to
drill and shoot in rock, but the steady swing of the four-pound
hammer (miners call them single-jacks) lamed his right arm so that
he could not strike a forceful blow. Moreover, he discovered that
twisting a drill in rock is not soothing to broken blisters. So, much as
he wanted to make Patricia rich in the shortest possible time,
protesting flesh prevailed upon him to knock off work for the time
being.
He was sitting on the edge of what would one day be an incline
shaft—when he had dug it deep enough—inspecting his blistered
hands. After several days of quiet the wind began to blow in gusts
from off the butte. Somewhere behind Gary and above him there
came a bellowing halloo that made him jump and slide into the open
cut. Again and again came the bellow above him—and after his first
astonishment Gary’s mouth relaxed into a slow grin.
“I’ll bet right there’s the makings of that spook Voice!” he said
aloud. “Up there in the rim rock somewhere.”
He climbed out of the cut and stood facing the cliff, listening. At
close quarters the call became a bellow with only a faint
resemblance to a Voice shouting hello. He remembered now that on
that first morning when he had searched for the elusive “man” on the
bluff, the wind had died before he had climbed very high. After that
he had not heard the Voice again that day.
He made his way laboriously up to the rim rock, listening always
to locate the exact source of the sound. The bluff was almost
perpendicular just under the rim, and huge bowlders lay where they
had fallen in some forgotten time from the top. Gary scrambled over
the first of these and confronted a narrow aperture which seemed to
lead back into the cliff. The opening was perhaps three feet wide at
the bottom, drawing in to a pointed roof a few feet above his head.
The Voice did not seem to come from this opening, but Gary’s
curiosity was roused. He went into the cave. Fifteen feet, as he
paced the distance, brought him to the rear wall—and to a small
recess where a couple of boxes sat side by side with a three-pound
coffee can on top and a bundle wrapped in canvas. Gary forgot the
Voice for the time being and began to investigate the cache.
It was perfectly simple; perfectly amazing also. The boxes had
been opened, probably in order to carry the contents more easily up
the bluff; the most ambitious man would scarcely want to make that