[PDF Download] Learning java functional programming 1st edition reese richard m full chapter pdf

Page 1


Learning Java Functional Programming

1st Edition Reese Richard M

Visit to download the full and correct content document: https://textbookfull.com/product/learning-java-functional-programming-1st-edition-rees e-richard-m/

More products digital (pdf, epub, mobi) instant download maybe you interests ...

Learning Network Programming with Java 1st Edition

Reese Richard M

https://textbookfull.com/product/learning-network-programmingwith-java-1st-edition-reese-richard-m/

Natural Language Processing with Java Community Experience Distilled 1st Edition Reese Richard M

https://textbookfull.com/product/natural-language-processingwith-java-community-experience-distilled-1st-edition-reeserichard-m/

EJB 3 1 Cookbook 1st Edition M Reese Richard

https://textbookfull.com/product/ejb-3-1-cookbook-1st-edition-mreese-richard/

Java for Data Science 1st Edition Reese

https://textbookfull.com/product/java-for-data-science-1stedition-reese/

Learning Java Beginning programming with java for dummies First Edition John Bach

https://textbookfull.com/product/learning-java-beginningprogramming-with-java-for-dummies-first-edition-john-bach/

Learning Java An Introduction to Real World Programming with Java Marc Loy

https://textbookfull.com/product/learning-java-an-introductionto-real-world-programming-with-java-marc-loy/

Learning Java An Introduction to Real World Programming with Java 5th Edition Marc Loy

https://textbookfull.com/product/learning-java-an-introductionto-real-world-programming-with-java-5th-edition-marc-loy/

Modern Java in Action Lambdas streams functional and reactive programming Raoul-Gabriel Urma

https://textbookfull.com/product/modern-java-in-action-lambdasstreams-functional-and-reactive-programming-raoul-gabriel-urma/

A Functional Approach to Java: Augmenting ObjectOriented Java Code with Functional Principles 1st Edition Ben Weidig

https://textbookfull.com/product/a-functional-approach-to-javaaugmenting-object-oriented-java-code-with-functionalprinciples-1st-edition-ben-weidig/

Learning Java Functional Programming

Create robust and maintainable Java applications using the functional style of programming

BIRMINGHAM - MUMBAI

Learning Java Functional Programming

Copyright © 2015 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: October 2015

Production reference: 1091015

Published by Packt Publishing Ltd.

Livery Place 35 Livery Street Birmingham B3 2PB, UK.

ISBN 978-1-78355-848-3 www.packtpub.com

Credits

Author

Richard M Reese

Reviewers

Jose Luis Ordiales Coscia

David Greco

Hossein Kazemi

Amar Potghan

Commissioning Editor

Veena Pagare

Acquisition Editor

Vivek Anantharaman

Content Development Editor

Susmita Sabat

Technical Editor

Prajakta Mhatre

Copy Editor

Charlotte Carneiro

Project Coordinator

Judie Jose

Proofreader Safis Editing

Indexer

Rekha Nair

Graphics

Jason Monteiro

Abhinash Sahu

Production Coordinator

Aparna Bhagat

Cover Work

Aparna Bhagat

About the Author

Richard M Reese has worked in both industry and academics. For 17 years, he worked in the telephone and aerospace industries, serving in several capacities, including research and development, software development, supervision, and training. He currently teaches at Tarleton State University, where he has the opportunity to draw on his years of industry experience to enhance his teaching.

Richard has written several Java books and a C pointer book. He uses a concise and easy-to-follow approach to the topics at hand. His Java books have addressed EJB 3.1, updates to Java 7 and 8, certification, jMonkeyEngine, and Natural Language Processing.

Richard would like to thank his daughter, Jennifer, for her numerous reviews and contributions; his wife, Karla, for her continued support; and the staff at Packt for their work in making this a better book.

About the Reviewers

Jose Luis Ordiales Coscia is a software engineer with much experience in both academia and the private industry. He has a master's degree in computer science, focusing his research on helping developers improve their service-oriented applications.

He has more than 7 years of experience working in backend development with Java and other JVM languages.

David Greco is a software architect with more than 27 years of working experience. He started his career as a researcher in the field of high-performance computing; thereafter, he moved to the business world, where he worked for different enterprise software vendors and helped to create two start-ups. He played different roles, those of a consultant and software architect and even a CTO. He's an enthusiastic explorer of new technologies, and likes to introduce new technologies into enterprises to improve their businesses. Over the past 5 years, he has fallen in love with big data technologies and typed functional programming—Scala and Haskell. When not working or hacking, he likes to practice karate and listen to jazz and classical music.

Hossein Kazemi is an entrepreneur and software engineer based in Amsterdam, the Netherlands. He holds a master's in artificial intelligence with a major in machine learning and minor in Natural Language Processing (NLP) from the University of Amsterdam. He has more than 5 years of hands-on experience in software development and has worked on projects for large-scale machine learning and NLP using Java and Scala.

Amar Potghan is a polyglot functional programming enthusiast. He has vast experience in building scalable distributed systems. Amar is currently working on Haskell and ClojureScript to build a next generation P2P lending platform for a fintech company in Singapore. Before that, he was working as a consultant at ThoughtWorks and as a senior software engineer for a couple of other global software consultancies where he worked on continuous delivery, microservices, big data, and analytics product development projects. Amar's current interests are functional programming, distributed systems, and machine learning.

Support files, eBooks, discount offers, and more

For support files and downloads related to your book, please visit www.PacktPub.com

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub. com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@packtpub.com for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

TM https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

Why subscribe?

• Fully searchable across every book published by Packt

• Copy and paste, print, and bookmark content

• On demand and accessible via a web browser

Free access for Packt account holders

If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.

Chapter 6: Optional and Monads

Debugging, and Testing

Preface

With the introduction of Java 8, many functional programming techniques have been added to the language. However, functional programming may seem unfamiliar to developers who are used to using imperative and object-oriented techniques. The new additions to Java 8 offer the opportunity to develop more maintainable and robust applications than that offered by earlier versions of Java.

The goal of this book is to introduce functional programming techniques to developers who are not familiar with this technology. You will be guided through the use of functional programming techniques with the help of numerous examples. Older imperative and object-oriented approaches will be illustrated and contrasted with equivalent functional programming solutions.

What this book covers

Chapter 1, Getting Started with Functional Programming, introduces the essential elements of functional programming as supported by Java 8. This includes the introduction of functional terms complemented by Java 8 examples.

Chapter 2, Putting the Function in Functional Programming, covers the types of functions found in functional programming languages such as high-order functions, first-class functions, and pure functions. The use of lambda expressions in support of functions is explained.

Chapter 3, Function Composition and Fluent Interfaces, addresses how to use functional composition. Also covered are fluent interfaces and the use of default methods.

Chapter 4, Streams and the Evaluation of Expressions, covers the basics of their creation and use. Streams are an important addition to Java.

Preface

Chapter 5, Recursion Techniques in Java 8, demonstrates recursion, a very useful functional programming technique. While not new to Java, we explore the topic in depth and examine the use of recursive lambda expressions.

Chapter 6, Optional and Monads, covers the use and the nature of monads in creating fluent interfaces and producing resilient code. The Optional class provides a better way of working with missing data.

Chapter 7, Supporting Design Patterns Using Functional Programming, illustrates design patterns. They play an important role in Java programming. The impact of the functional style of programming and lambda expressions is illustrated.

Chapter 8, Refactoring, Debugging, and Testing, demonstrates how these tools have been affected by the new functional programming techniques and how IDEs support them. These are valuable tools in the development process.

Chapter 9, Bringing It All Together, summarizes many of the functional programming techniques presented earlier that are used in the creation of a demonstration application. Such an application provides a concise illustration of how these techniques support the development of robust and maintainable software.

What you need for this book

Java SDK 1.8 is needed for the functional programming examples encountered in the book. Some of the examples use NetBeans 8.02 and Eclipse IDE for Java developers, Mars Release Version 4.5.0.

Who this book is for

This book is for developers who are already proficient in Java and want to learn how to use the functional programming features of Java 8. Familiarity with basic Java object-oriented programming concepts is all that is needed. You will learn how to apply lambda expressions and other functional programming techniques to create a more elegant and maintainable code.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Preface

Code words in text are shown are follows: "As you may remember, the forEach method accepts a lambda expression which matches the Consumer interface's accept method."

A block of code is shown as follows:

list.forEach(new Consumer<String>() { @Override public void accept(String t) { System.out.println(t); } });

The output of code sequences is formatted as shown here:

Starting FPS Game

Generating FPS Image

Rendering FPS Image

Updating FPS Game

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "There is the text form as entered by the user such as: drop Axe."

Warnings or important notes appear in a box like this.

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail feedback@packtpub.com, and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www. packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub. com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/ content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at copyright@packtpub.com with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Preface

Questions

If you have a problem with any aspect of this book, you can contact us at questions@packtpub.com, and we will do our best to address the problem.

Getting Started with Functional Programming

Functional programming languages have been used successfully for decades and present a different and often more elegant way of expressing the program logic. Functional languages, such as Lisp, Clojure, or Haskell, incorporate techniques that may seem odd and hard to follow by programmers who are used to imperative programming techniques.

A language such as Java, while not initially developed with a functional orientation, can incorporate functional techniques. This is the major change to the language made with the release of Java 8. Java now incorporates imperative, procedural, object-oriented, and functional techniques.

It is possible to write a non-object-oriented program in Java. Likewise, it is possible to write a nonfunctional program in Java 8. The goal of this book is to enlighten the reader to the nature of functional programming techniques and how to incorporate these techniques in Java 8 applications.

We will start with a discussion of the attributes commonly associated with functional programming. From there, we will examine the support, Java provides for developing applications using a functional-style programming approach.

A predominant feature of functional programming languages is the use of functions. The term, function, is generally understood to be:

• A way of expressing an algorithm

• A mathematical function

• Where the goal is to avoid state changes and mutable data

Getting Started with Functional Programming

In functional programming, applications are constructed using only pure functions. A pure function is a function which does not have side effects. A side effect occurs when a function does something else besides simply returning a value, such as mutating a global variable or performing IO. In this chapter, we will examine the major aspects of functional programming including:

• Functions and function composition

• Fluent interfaces

• Strict and non-strict evaluation

• Persistent data structures, monads, and the Optional class

• Recursion and parallelism

This is followed by the support Java 8 provides for functional programming, including:

• Lambda expressions

• Default methods

• Functional interface

• Method and constructor references

• Collections

In addition, to our discussion of functional programming support as provided by Java 8, refactoring, debugging, and testing Java 8 code are also important topics, which need to be addressed. These topics are covered in Chapter 8, Refactoring, Debugging, and Testing

So, let's begin with an overview of what constitutes the functional programming approach.

Aspects of functional programming

Functions can be simple or complex, but simpler functions are preferred. The function should ideally not change the state of memory or perform I/O, and consequently work with immutable data. These later two concepts are explored in Chapter 6, Optional and Monads

There are several aspects of functional programming languages that we will explore here. They include:

• Functions

• Function composition

• Fluent interfaces

• Strict versus non-strict evaluation

• Parallelism

• Persistent data structures

• Recursion

• Optional and monads

Each of these concepts will be introduced in the following sections. We will explore the nature of each concept, explain why it is important, and when practical provide simple examples using Java.

Functions

Functions are the foundation of functional programming languages. They play a central role in supporting other functional programming concepts. In this section, we will introduce many of the terms used to describe functions including high-order, first-class, and pure functions. The concepts of closure and currying will also be explained.

First-class and high-order functions are associated with functional programming. A first-class function is a computer science term. It refers to functions that can be used anywhere a first-class entity can be used. A first-class entity includes elements such as numbers and strings. They can be used as an argument to a function, returned from a function, or assigned to a variable.

High-order functions depend upon the existence of first-class functions. They are functions that either:

• Take a function as an argument

• Return a function

Java 8 has introduced the concept of lambda expressions to the language. These are essentially anonymous functions that can be passed to and returned from functions. They can also be assigned to a variable. The basic form of a lambda expression follows where a parameter, such as x, is passed to the body of the function. The lambda operator, ->, separates the parameter from the body. This function is passed a value, which is multiplied by two and then returned, as follows:

x -> 2 * x

In this lambda expression, it is assumed that an integer is passed and that integer is returned. However, the data type is not restricted to an integer as we will see later. In the following lambda expression, an argument is passed and nothing is returned:

x->System.out.println(x)

Getting Started with Functional Programming

Lambda expressions must be used in the proper context. It would not be appropriate to pass a lambda expression, which returns a value to a method, to a function that cannot use the returned value.

We can use the previous expression in many places that expect a single value being passed and nothing to be returned as shown next. In the following example, an array of integers is converted to a list. The lambda expression is then used as an argument to the List class's forEach method, which displays each element of the list. The forEach method applies the lambda expression to each element in the list, avoiding having to create an explicit loop to achieve the same effect:

Integer arr[] = {1,2,3,4,5};

List<Integer> list = Arrays.asList(arr); list.forEach(x->System.out.println(x));

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

The output will list the numbers one to five on separate lines.

Changing a program's state is avoided in functional programming. Calling a function with the same input values should result in the same behavior each time. This makes it easier to understand the function. Imperative programming changes the state using statements such as the assignment statement.

A pure function is a function that has no side effects. This means that memory external to the function is not modified, IO is not performed, and no exceptions are thrown. With a pure function, when it is called repeatedly with the same parameters, it will return the same value. This is called referential transparency.

With referential transparency, it is permissible to modify local variables within the function as this does not change the state of the program. Any changes are not seen outside of the function.

Advantages of pure function include:

• The function can be called repeatedly with the same argument and get the same results. This enables caching optimization (memorization).

• With no dependencies between multiple pure functions, they can be reordered and performed in parallel. They are essentially thread safe.

• Pure function enables lazy evaluation as discussed later in the Strict versus non-strict evaluation section. This implies that the execution of the function can be delayed and its results can be cached potentially improving the performance of a program.

• If the result of a function is not used, then it can be removed since it does not affect other operations.

There are several other terms associated with functions, such as the term closure This refers to a function passed around along with its environment. The environment consists of the variables it uses. Java 8 supports a form of closure, and will be illustrated in Chapter 2, Putting the Function in Functional Programming

Currying is the process of evaluating multiple arguments of a function one-by-one, producing intermediate results. In the process, we introduce a new function with one less argument than the previous step. For example, let's start with this function:

We can evaluate it for the value of 3 and 4 as follows, returning a result of 7:

If we substitute 3 for x we get:

Next, if we define g(y) as:

Then, the following is also true:

We reduced the number of arguments from two to one. Using a value of 4 for y yields the original result of 7. The process of currying, and partially applying functions, permit high-order functions to be used more effectively. This will become clearer in Chapter 2, Putting the Function in Functional Programming

Function composition

Imperative programming places emphasis on a step-by-step process to implement an application. This is typified by a logical set of steps where code is executed using basic control constructs and is often encapsulated in functions or procedures.

Functional programming places more emphasis on how these functions are arranged and combined. It is this composition of functions, which typifies a functional style of programming. Functions are not only used to organize the execution process, but are also passed and returned from functions. Often data and the functions acting on the data are passed together promoting more capable and expressive programs.

We will illustrate this technique using the Function interface as defined in the java. util.function package. This interface possesses a compose and andThen methods. Both of these methods return a composed function.

The compose method will execute the function passed to it first, and then uses its result with the function the compose method is executed against. The andThen method will execute the first function and then execute the function passed as an argument to the andThen method.

The next code sequence demonstrates the compose method, which is passed as a function to take the absolute value of a number. The absThenNegate variable is assigned a function that will also negate the number. This variable is declared as a Function type, which means that the function assigned to it expects to be passed as an integer and returns an integer.

This function will execute the argument of the compose method and the Math class's abs method first, against some value, and then apply the negateExact method to this result. In other words, it will take the absolute value of a number and then negate it. Both of these methods are expressed as method references, which are new to Java 8. A method reference consist of the class name followed by a set of double colons, and then a method name providing a simpler form of method invocation:

Function<Integer,Integer>absThenNegate = ((Function<Integer,Integer>)Math::negateExact) .compose(Math::abs);

This is illustrated with the following sequence. The Function interface's apply method is used to invoke the composed function:

System.out.println(absThenNegate.apply(-25)); System.out.println(absThenNegate.apply(25));

Both of these statements will display a -25. In the first statement, the absolute value of a -25 is obtained and then negated. The second statement works the same way except its argument is +25

The negateThenAbs variable that follows, illustrates the andThen method. The function used as an argument to the andThen method is applied after the first function is executed. In this case, the negateExact method is executed first and then the abs function is applied:

Function<Integer,Integer>negateThenAbs = ((Function<Integer,Integer>)Math::negateExact) .andThen(Math::abs);

System.out.println(negateThenAbs.apply(-25));

System.out.println(negateThenAbs.apply(25));

The output of both display statements will be 25

We could have obtained the same results with a series of imperative statements. However, this does not result in as much flexibility as can be obtained using function composition. The ability to pass functions will provide the enhanced flexibility. We will postpone a detailed discussion of this approach until Chapter 3, Function Composition and Fluent Interfaces

Fluent interfaces

Fluent interfaces constitute a way of composing expressions that are easier to write and understand. A fluent interface is often implemented using method chaining, sometimes called method cascading, where the returned value is used again in the same context.

In Java 8, the use of fluent interfaces is found in numerous places. We will illustrate this style with an example using the new Date and Time API.

Suppose we want to calculate a new date that is 2 years in the future, minus 1 month plus 3 days. We can use the following code sequence to achieve this result. The LocalDate class's method now returns an instance of the LocalDate class representing the current date. This date is the base for creating a new day called futureDate:

LocalDate today = LocalDate.now();

LocalDate futureDate = today.plusYears(2); futureDate = futureDate.minusMonths(1); futureDate = futureDate.plusDays(3); System.out.println(today); System.out.println(futureDate);

Getting Started with Functional Programming

This will generate the following output:

2015-03-22

2017-02-25

Contrast this with the next code sequence, which takes advantage of the APIs fluent interface and produces the same output:

LocalDatefutureDate = LocalDate.now()

.plusYears(2)

.minusMonths(1)

.plusDays(3);

The code flow is easy to read and flows in a more natural way. You will see repeated usage of fluent interfaces in the book. Streams use this approach consistently.

Strict versus non-strict evaluation

Functional languages can be classified as either using strict or non-strict evaluation of expressions. With strict evaluation, sometimes called eager evaluation, the expressions are evaluated as they are encountered.

With non-strict evaluation, they are not evaluated until necessary. Non-strict evaluation is sometimes called lazy evaluation. However, these terms are not always strict synonyms. Non-strict evaluation is concerned with the semantics of the expression, while lazy evaluation deals more with how the expression is evaluated.

Lazy evaluation is supported using streams. A stream can be thought of as a series of elements that flow like a river or stream. They add a convenient means of processing data in an easy-to-use and natural manner. The stream concept is support in Java 8 with the Stream class.

In the following sequence, a stream is created by generating five random numbers, sorting these numbers, and then displaying them:

Random random = new Random(); random.ints()

.limit(5)

.sorted()

.forEach(x->System.out.println(x));

Another random document with no related content on Scribd:

CHAPTER XXV.

A TERRIBLE COMPACT.

Perry Lamont, the millionaire, stood underneath the brilliant chandelier in his luxurious library, apparently waiting for some one. He looked anxiously toward the door, and when it opened his eyes glittered.

The person who entered the room was his son.

For half a second father and son stood face to face, and then the former waved the other to a chair.

Claude, looking a little worse for the night out, complied, and waited for his father to speak.

“Who is this man Richmond?” asked Lamont, senior.

The young man started.

“He is your friend, I believe?”

“He is, and he is a nice gentleman,” said Claude.

“I judge so,” and a smile came to the father’s lips.

“What has happened? You speak sarcastically this morning.”

“Do I? Well, I want you to give up this ‘nice gentleman.’”

Claude looked away, but in a moment his gaze came back to his father’s face.

“This man is a rascal,” spoke up the millionaire.

“That’s a pretty bold charge against a friend of mine.”

“Bold or not, it’s true.”

“Who is the accuser?”

“Never mind that.”

“I demand to know Mr Richmond has a right to face his accuser, and he will do so.”

“But you haven’t denied the charge of your friend.”

“I do it now.”

“Then he is a nice gentleman still, is he?”

“He is, sir.”

Claude flushed.

“I am the accuser,” and the face of the millionaire grew white. “I call him a rascal.”

“Upon what grounds?”

“He tried to blackmail me.”

“Mr. Richmond?”

“Yes, sir. That man came here but a few days ago and wanted to rob me of ten thousand dollars.”

“Impossible!” cried Claude, feigning astonishment.

“It is true, and what is more, he hinted that you had committed a great crime.”

“Come, come; you must have been dreaming.”

“I was as wide awake then as I am now.”

Lamont, senior, smiled knowingly.

“You must drop this black bird.”

“I am of age and have the right to choose my friends,” was his son’s answer

“Then keep him and yourself in the future.”

The young man gazed at his father in wide-open astonishment.

“You certainly don’t mean that,” he said.

“I do. He is your friend, you say. Keep him and yourself. I guess that’s plain.”

Claude Lamont arose and crossed the room.

“You don’t know what you do,” he cried.

“I know what I do. It is either lose this friend, as you call him, or lose your fortune.”

“He never tried to blackmail you.”

“He did!” thundered the nabob. “In this very room he wanted to sell the so-called secret for ten thousand dollars. I drove him away. I wouldn’t have anything to do with the scoundrel. But it seems you do. You are with him night and day, and you are old enough to know that you can’t play with pitch and not become defiled.”

Claude smiled derisively at this, and for a moment was silent.

“Look here,” he suddenly said, “I can’t give this man up. He knows too much.”

“What’s that?” cried Lamont, senior. “Do you admit that you are in his power?”

“I didn’t say so. I only remarked that I can’t throw him to one side. He knows too much.”

“Against whom?”

“Against the house.”

“It cannot be.”

“I’m afraid it’s true. This man is my friend, and I have been keeping near him for a purpose, and that purpose the salvation of the good name of Lamont.”

A strange and eager light seemed to come into the millionaire’s eyes, and for half a second he did not continue.

“Sit down,” he said. “Tell me what this man knows.”

Claude went back to the chair.

“He knows a good deal more than we can afford to let him tell,” he said. “I don’t say that Richmond will tell the secret on the street or

anything of that kind, but we can’t afford to let him have the opportunity.”

“In God’s name, what is the secret?”

“Of course he never told me, but I only guess at it from hints he has dropped while in his cups. It’s a terrible thing, if it’s true—a fearful secret, father.”

“Out with it. I am strong, you see, and can listen to any recital you make.”

Claude crossed the room, and looked cautiously into the hall.

No one was there.

Coming back, he resumed his seat in the chair and looked at the white-faced man opposite.

“Whatever became of Aunt Hester?” he asked.

The expression that came into Perry Lamont’s face was most startling.

Every vestige of color left it, and it became as white as a marble statue.

“Who ever told you that I had a sister named Hester?” he asked.

“Never mind that. I only asked the question.”

“Is this some of your friend’s work?”

“That is a part of his secret. He says he has certain papers that will startle the world, that he has in his possession a certain confession or a family history written out by an old woman who called herself ——”

Young Lamont paused, for his father was gasping like a man fighting for his breath.

“Go on. Tell me all. What did this woman call herself?” he cried.

“Mother Flintstone,” coolly said the son. “She lived in Hell’s Kitchen, and after being threatened a number of times—in spite of the

protection of Carter’s assistants—she was murdered a few nights ago.”

“Yes, yes. I saw something of that in the newspapers.”

“Well, from what I have heard Richmond say in a dark way when in his cups he can prove that Mother Flintstone, the old fence, was your sister.”

“Great heavens!” cried Perry Lamont. “Has he got the documents left by this woman?”

“I fear he has.”

“But he didn’t offer them to me.”

“I can’t say as to that.”

“He only offered to keep the knowledge of your doings from the world for ten thousand dollars.”

“But he has the papers now. I am confident of that.”

“Will he sell them?” eagerly asked the millionaire.

“He might.”

“For how much?”

“You must negotiate with him.”

“Look here, Claude, my boy. Can’t you get possession of those papers?”

“How?”

“Any way, I don’t care how you get them.”

“You wouldn’t want me to rob my friend?”

“I say I don’t care how you get them.”

“But he would still possess the secret.”

“We’ll take care of him after the documents have been found. How did he get them? Was he familiar with Mother Flintstone?”

“I don’t know.”

“Merciless villain! He holds the peace of our house in his hands. The man is the quintessence of rascality. Talk about your polished blackmailers. He stands at the head of the procession. I’ll hand him over to the police at once.”

“Try it, and the whole thing will come out.” Lamont, senior, gasped again.

“Where does Richmond board?”

“He changes his place often. I don’t believe he sleeps two nights in the same place.”

“Like the sultan. But, look here, my boy. You don’t want the good name of our house destroyed?”

“One of the last things I want to see,” said the young rake.

“Then help me destroy this man. Help me to get those papers and silence him.”

“It is true, then?”

“It is true.”

“Mother Flintstone was your sister?”

“Yes, yes. She was Hester, the sister who contracted a poor marriage years ago and finally drifted into crime.”

Claude Lamont seemed struck with a thunderbolt, and for some time he sat in the presence of his father, dazed and speechless.

“I had hoped the truth would never come out,” continued the millionaire. “I accidentally discovered a year ago who Mother Flintstone was, but I said nothing. I would have given her thousands to have thrown herself from the bridge or to have left the city, but I dared not approach her. And so she left a confession behind; she has left the secret to a scoundrel like this George Richmond. Why, this man has more names than one.”

“A good many people have nowadays,” answered Claude.

“Well, he must be silenced somehow.”

“With money?”

“Not if I can help it. I would like to know what sort of communication Mother Flintstone left.”

“It seems to me the best way to deal with the secret holder is to come to his terms,” suggested Claude.

“And be bled every now and then? I’ll defy him first!”

“Come, come. You can’t afford to do that. Think of our station in society. Sister is on the eve of marriage, and mother’s health is not what it used to be. We must come to his terms to save the house of Lamont.”

The millionaire began to pace the floor like a wild beast.

“What will you take to strangle the scoundrel, Claude?” he suddenly exclaimed, halting before his son. “You have every opportunity. Name your price.”

“You don’t really mean that?” cried the young man.

“I do, every word of it. What will you take to silence this man forever?”

“Two hundred thousand cash in hand.”

“Done!” exclaimed the millionaire. “That’s a bargain!”

CHAPTER XXVI.

THE DARK JAILERESS

AGAIN.

It was a cool compact.

Perry Lamont made answer to his son with all the cleverness of a practiced villain, and Claude accepted it in the same manner.

“I want this man silenced,” continued the millionaire. “He must not possess this secret.”

“Just as you say,” said Claude, picking up a cigar and coolly lighting it.

“He must not, I say. You’ve agreed to finish him, and when you’ve done so the money is yours.”

“Couldn’t you give me a little check now?” asked the son.

Perry Lamont took a check book from the desk and opened it as he looked at his son.

“How much?”

“Say five thousand. I may need the money in the venture, you know.”

Without more ado the nabob drew up a check for five thousand dollars, and passed it across the table.

“This business must not lag,” said he. “While that man lives he is dangerous.”

Five minutes later the young man stood on a corner in another part of the city. He was smoking complacently and apparently waiting for some one, for he watched the door of a well-known resort.

Presently the door opened and George Richmond came out.

Claude joined him at once, and the pair walked away together.

In a little while they seated themselves at a table in a room not far from the corner, and Claude threw the check upon the table.

“Jehu! did you make it?” cried Richmond.

“I did.”

“How?”

The young scamp smiled.

“It’s blood money,” he said.

“Blood money?” exclaimed Richmond. “In Heaven’s name, whose blood does it mean?”

“Yours!”

“Come, what joke is this?”

“It is no joke. I never joke on serious matters like this.”

The eyes of the two men met.

“This check is signed by your father, and yet you tell me that it is blood money.”

“That’s precisely what it is. He’s hired me to kill you.”

George Richmond broke into a laugh and leaned back in his chair.

“You don’t look like it, boy,” he cried. “Well, if I’m to be killed, why don’t you do it now?”

Claude reached forward and picked up the check.

“I’m to have a cool two hundred thousand for the job,” said he. “Just think of it! You’re an important person.”

“Hang me if I ain’t. Why does the old man want me out of the way?”

“You hold the secret, and he believes you have the papers left by Mother Flintstone.”

“You gave him that gaff, did you?”

“Yes, in great shape.”

“I hardly thought you’d do it. But since you have I suppose you’re to furnish proofs that I’ve been killed.”

“Of course.”

“You are not expected to furnish the corpse, I hope?”

“No; not quite that. But he’s to have some sort of proofs, and then we’ll get the two hundred thousand.”

For an hour these men kept their heads together and talked in low tones.

They discussed first one plan and then another, and when they at last adjourned and stepped out upon the street they seemed satisfied about something.

Not far from the place of meeting a hand was laid upon Claude Lamont’s arm, and he looked into the face of a tall woman.

“You?” he cried, for he was alone, having separated from Richmond a few moments previous.

“Yes? Why not?”

“I thought I left you in the nest with Margie.”

“So you did, but there isn’t any nest now.”

“No nest? What’s happened?”

“The old place is in ashes.”

Lamont uttered a startled cry, and looked at the woman, who did not speak.

“You weren’t to hurt the girl, you know?” said he.

“That’s true, but I couldn’t help it.”

“But tell me. Come in here. No one will listen to us. Now, what has taken place?”

Nora took a long breath and began.

“The girl got almost unruly. I got her up to bed, but she faced me and threatened.”

“Well, you shouldn’t have paid any attention to her words.”

“I couldn’t help it. She mentioned a name that drove every vestige of color from my face.”

“An old enemy’s name, eh?”

“Yes; she spoke of a detective whom I fear with all my soul. She spoke of Carter.”

“And made you chicken-hearted, eh? Pshaw, woman!”

“I couldn’t help it, I say. It filled me with fear, and I broke away.”

“Well?”

“By and by the room became still, and I found that she was asleep at last.”

“That’s good.”

“In the room below I upset the lamp.”

“The devil you did, woman! You must have been badly frightened.”

“I was. In an instant it seemed the fire was everywhere. I saw it mount the stairs and dart toward the girl’s room. Fear almost paralyzed me. I tried to get upstairs, but failed. The fire was everywhere. It filled the whole house, it seemed. I could no more stop its progress than I could stop the river yonder. I fled for my life.”

“And left Margie to perish in the flames?”

“Got help me, I did.”

Lamont leaned back and looked at the woman, whose face was deathly white.

“Did she perish?” he asked at last.

“She must have died in the old house. I did not stay to look after her. Fear lent speed to my limbs, and I ran like a deer. Not for the world would I have gone back.”

“You’ve killed the girl!” hissed Claude Lamont. “You’ve made a murderess out of yourself.”

Nora did not speak, but looked into the young man’s face and exposed anew the whiteness of her own.

“I suppose you haven’t been there since?” he said.

“What, go back to that spot? Never!”

Claude Lamont drained the glass at his elbow and seemed to take a long breath.

“What makes you fear this man, Carter? What did he ever do that gives you the chills?”

“That’s my secret,” cried the woman, half defiantly.

“What makes him your enemy, and, pray, what did you do that his name terrifies you?”

She did not answer him.

“Look here!” suddenly said Claude. “If you’ve killed the girl by your faint heart I’ll hold you responsible.”

“Just as you please,” was the reply.

Nora seemed to be getting her old nerve back, for she spoke with spirit, and her cheeks flushed for the first time.

“You never got such orders from me,” he went on.

“I know it. I dropped the lamp——”

“Come, no excuses,” interrupted the young man. “I shall hold you responsible—guilty of murder.”

“Just as if you never did anything that has a shady side,” hissed the woman. “You’re a nice man to talk thus. What have you done that makes an angel out of you, I should like to know?”

“No accusations, woman.”

“Very well. Will you hand me over to the police? Will you tell the inspector that I am the last person who saw the girl alive? I guess not!”

“Don’t dare me.”

“What if I tell them that Margie was Mother Flintstone’s granddaughter——”

“She wasn’t!” flashed Claude Lamont.

“You take it up in a jiffy,” grinned Nora. “If she wasn’t why did you resent my words so soon?”

For half a second Lamont watched the dark face before him, and then he said:

“We’ll call it quits. After all, perhaps you couldn’t have helped it. The lamp fell from your hand, did it?”

“I told you once.”

“And you couldn’t stop the flames?”

“I couldn’t. I’d give my eyes if that girl was alive to-day. I did not do it intentionally. My evil genius must have been on the watch.”

“We’ll say so, at any rate, Nora.”

It was the first time he had spoken her name during the interview, and his voice was considerably softened.

“The department may have reached the fire in time to save the girl,” he went on.

“No, no! she perished. The whole house was in flames by the time I got away. I’m going now.”

“Still afraid of the detective’s shadow?”

“Never mind the detective. I’m going, I say.”

“Do you mean that you’re going away?”

“Yes—to put ten thousand miles between me and that infernal crime of mine.”

Lamont drew forth his pocketbook and began to count out some bills.

“Put up your money. It’s blood money!” cried Nora. “I wouldn’t touch a penny of your father’s wealth. I don’t want money. I’ve got all I shall need.”

“Then you’re going but a short distance?”

“Yes; not far.”

The last word seemed to come from between clenched teeth, and a desperate look settled on the woman’s face.

“Then here’s to you, Nora, and good luck go with you,” and Lamont held out his hand.

She pushed it away, with a look of disdain.

“It’s like your money. There’s blood on it, too!” she exclaimed. “Some day you’ll wish you had never had anything to do with this game of crime. Good-by.”

She sprang up, gave him another look and vanished.

“She’s mad, but it’s all right. She will try the river,” he laughed.

CHAPTER XXVII.

FOUND IN THE TIDE.

After the scene the detective had witnessed through Bristol Clara’s assistance he made his way to another part of the city and entered a little house, where he was confronted by Billy, the street rat.

The detective wanted to ascertain if the boy had picked up anything new, and his first words startled him.

“They didn’t burn her up, Mr. Carter.”

“Didn’t burn who up, Billy?”

“Margie, you know.”

The detective as yet had heard nothing of the fire at which Margie Marne nearly lost her life, and he lost no time questioning Billy.

The boy had heard of the fire through a fireman, and had gone direct to the hospital, where he had held an interview with the girl herself.

“I’ll see her, too,” said Nick. “This is important, Billy, and Margie must be seen.”

Imagine the astonishment of the girl when she saw Carter walking up the aisle toward her.

A smile of pleasure overspread her face, and she held out her hand.

“This is indeed a great pleasure,” cried Margie. “We’ve been sending after you, and just when we give you up here you come. I’ve been within the shadow of death.”

“So Billy told me.”

“I wonder if Nora, my jaileress, escaped?”

“We will find that out by and by. Tell me the whole story, Margie, and then we will see what can be done.”

The girl proceeded, and gave the detective the entire story of her adventures while in the hands of Claude Lamont and under Nora’s care, and Nick listened attentively.

“I think I can locate your jaileress,” said he, at the end of Margie’s narrative.

“Do so. She didn’t treat me badly, only she was true to her master. She started at the mention of your name, though.”

“Did she?” smiled Carter.

“It drove every vestige of color from her face.”

“She’s met me somewhere, then,” said the detective. “I want to see Nora.”

Half an hour later the detective reached the scene of the fire, and looked upon the ruins of Margie’s prison.

The house had been entirely destroyed, and some of the neighbors seemed glad that it was so.

“None of us liked the tall, dark-faced woman, with the little, red scar over her left eye,” said a woman who lived near the place, and whom the detective addressed.

“What did you call her?”

“Oh, we never called on her at all. She was very exclusive.”

“Had no visitors, eh?”

“Yes, sometimes. A man would drop in, generally after dark, and stay about half an hour.”

“You saw him, did you?”

“I couldn’t help it, you see, from where I live.”

“What was he like?”

“He was younger than the woman. He was always well dressed, like a swell nabob, and carried himself like a sport.”

“Claude again,” thought Carter. “You never saw the woman go out?”

His last question was addressed to the neighbor

“Not often. She remained at home, and seemed to attend to her own business.”

“You’re sure about that scar, are you?”

“Bless you, yes. I saw it more than once, when we happened to meet in the little grocery on the corner yonder. It was a real, red scar.”

Carter handed the woman a piece of money, which she did not refuse, and went away. He went direct to police headquarters and to the famous rogues’ gallery.

There he began to look through the large albums containing the faces of criminals and suspects, and for nearly an hour he turned the thick leaves industriously.

At last he stopped and leaned over the page.

His eyes seemed to become fastened upon a certain face, that of a woman, angular and dark.

Turning to the proper entry he read a description of the woman whose photographed face was before him, and he seemed to smile when he noted that she had a brilliant red scar over the left eye.

“This must be our old friend,” said the detective. “This is Mag Maginnis, the shoplifter, whom I sent up the river five years ago. I didn’t see the scar then. She got it since, and the photograph is the second one she’s had the honor of having in this collection. So Mag started at mention of my name by Margie. No wonder. I filled her with terror when I caught her in the dry-goods district in the very act of plundering a counter. We’ll see.”

He shut the album and walked away.

The detective never let a trail get cold, and therefore he proceeded to a part of the city where he hoped to strike Mag’s trail.

“The Lord deliver us! Here’s Mr. Carter!” cried a woman’s shrill voice, as the detective opened a door and confronted a female at a table.

The woman had seen better days, for an air of refinement still lingered about the place, the appointments of which were poor. She sat bolt upright, looking into the face she had instantly recognized, and the detective stood for a moment at the door.

“You don’t want me, I hope?” asked the woman.

“Not at all, Sybil.”

“That’s good, but I couldn’t see how you would, seeing that I’ve been good for three years.”

“I know that, and you’re to have all the credit, too.”

“Thank you, Mr. Carter. But if you had come a little sooner you might have seen an old friend,” and the woman laughed.

“What old friend was here, Sybil?”

“It was Mag. You remember her?”

In spite of his coolness the detective started.

“Yes,” continued the woman called Sybil, “Mag was here, and bade me good-by. She’s going off. What’s happened, Mr. Carter? Mag wouldn’t explain.”

“Where did she go, Sybil?” asked the detective, paying no attention to the woman’s query.

“She did not tell me. But I never saw Mag in just the way she was. She said she was tired of life, tired of pulling other people’s chestnuts out of the fire, and now and then she acted like a person on the verge of insanity. She may have gone to the river, for once or twice she mentioned it in despairing tones.”

“How long has she been gone?” eagerly questioned the detective.

“Barely twenty minutes.”

“I’ll see you later, Sybil,” cried the detective, turning to the door. “I must find Mag, if possible.”

“She’s Nora now, you know.”

“Yes, yes.”

“She dropped ‘Mag’ months ago, or soon after she came down the river.”

“But she’s Mag yet,” smiled Carter, and in another second the woman was left alone wondering why he wanted to see Nora so badly.

There were many chances against Nick finding the woman he sought, but he did not despair.

The piers of New York are many and long.

From them thousands have leaped to their death, or been thrown into the waters after dark by those whose hands are red with crime.

More than once the detective’s trail had taken him to the docks, and there he had picked up more than one clew.

Every dock in the city was known to Carter.

While among them he was at home, and knew where they began and ended.

The bare thought that this old criminal had gone to the river in a fit of remorse, for he doubted not that she thought Margie had perished in the fire, urged him on.

Of course, if Nora intended to commit suicide she had had ample time to carry out her plans, but still there was a chance that she had changed her mind.

The detective reached the river at a spot nearest the house he had just left.

He could see nothing of the hunted woman, and no crowd such as gathers on the piers when the body of a suicide has been discovered greeted him.

The detective walked along the river front for some distance with his senses on the alert.

All at once he caught sight of something floating in the water, and he stopped suddenly and leaned forward.

It did not take him long to see that the object was the body of a woman, and Carter called a policeman who stood a short distance away.

“That’s the same woman!” cried the patrolman the moment he caught sight of the body.

“What woman?” asked Carter.

“Why, sir, the woman who came down here three hours ago and asked me some fool questions about the river.”

“Well?”

“I didn’t notice which way she went. But that’s her.”

Nick and the policeman managed to bring the body against the logs of the pier, and the detective clambered down and hauled it up.

The burden was a heavy one, but the detective’s hand did not lose its grip, and in time the body lay on the wharf, which it drenched.

The detective looked into the long face, and his gaze alighted upon a little scar over the left eye.

“This is Nora—Margie’s jaileress, but she’s Mag Maginnis, the old offender. She’s not to blame entirely for this. The hand of her master drove her to suicide, and he shall pay for it!”

Carter seemed to speak the last words through clenched teeth, and his voice told that he meant every word he said.

The policeman in the meantime called the patrol, and Nick had extracted from the woman’s bosom a little flat package like a memorandum, which he hastily transferred to his own pocket.

“That’s the end of one poor, storm-tossed soul,” muttered the detective as he walked away “I found Mag sooner than I expected, but we’ve not heard the last of her.”

Half a block from the river front the detective nearly ran against a man who came out of a house with a reputation none of the best and walked off.

Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.