Functional Thinking_ Paradigm Over Syntax [Ford 2014-07-20].pdf

(7790 KB) Pobierz
Functional Thinking
Neal Ford
Functional Thinking
by Neal Ford
Copyright © 2014 Neal Ford. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are
also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/
institutional sales department: 800-998-9938 or
corporate@oreilly.com.
Editors:
Mike Loukides and Meghan Blanchette
Production Editor:
Kristen Brown
Copyeditor:
Eileen Cohen
Proofreader:
Jasmine Kwityn
July 2014:
First Edition
Indexer:
Judith McConville
Cover Designer:
Karen Montgomery
Interior Designer:
David Futato
Illustrator:
Rebecca Demarest
Revision History for the First Edition:
2014-06-26:
First release
See
http://oreilly.com/catalog/errata.csp?isbn=9781449365516
for release details.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly
Media, Inc.
Functional Thinking,
the image of a thick-tailed greater galago, and related trade dress are
trademarks of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a trademark
claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and author assume no
responsibility for errors or omissions, or for damages resulting from the use of the information contained
herein.
ISBN: 978-1-449-36551-6
[LSI]
Table of Contents
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii
1. Why. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Shifting Paradigms
Aligning with Language Trends
Ceding Control to the Language/Runtime
Concision
2
4
4
5
2. Shift. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
A Common Example
Imperative Processing
Functional Processing
Case Study: Number Classification
Imperative Number Classification
Slightly More Functional Number Classification
Java 8 Number Classifier
Functional Java Number Classifier
Common Building Blocks
Filter
Map
Fold/Reduce
Synonym Suffering
Filter
Map
Fold/Reduce
Iteration to Higher-Order Functions
Closures
11
11
12
17
17
19
21
22
24
24
25
29
31
31
34
36
39
40
3. Cede. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
iii
Zgłoś jeśli naruszono regulamin