万本电子书0元读

万本电子书0元读

顶部广告

Swift Functional Programming - Second Edition电子书

售       价:¥

1人正在读 | 0人评论 9.8

作       者:Dr. Fatih Nayebi

出  版  社:Packt Publishing

出版时间:2017-04-26

字       数:36.9万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
Bring the power of functional programming to Swift to develop clean, smart, scalable and reliable applications. About This Book ?Written for the latest version of Swift, this is a comprehensive guide that introduces iOS, Web and macOS developers to the all-new world of functional programming that has so far been alien to them ?Get familiar with using functional programming alongside existing OOP techniques so you can get the best of both worlds and develop clean, robust, and scalable code ?Develop a case study on example backend API with Swift and Vapor Framework and an iOS application with Functional Programming, Protocol-Oriented Programming, Functional Reactive Programming, and Object-Oriented Programming techniques Who This Book Is For Meant for a reader who knows object-oriented programming, has some experience with Objective-C/Swift programming languages and wants to further enhance his skills with functional programming techniques with Swift 3.x. What You Will Learn ?Understand what functional programming is and why it matters ?Understand custom operators, function composition, currying, recursion, and memoization ?Explore algebraic data types, pattern matching, generics, associated type protocols, and type erasure ?Get acquainted with higher-kinded types and higher-order functions using practical examples ?Get familiar with functional and non-functional ways to deal with optionals ?Make use of functional data structures such as semigroup, monoid, binary search tree, linked list, stack, and lazy list ?Understand the importance of immutability, copy constructors, and lenses
目录展开

Title Page

Copyright

Credits

About the Author

About the Reviewer

www.PacktPub.com

Customer Feedback

Dedication

Preface

What this book covers

What you need for this book

Who this book is for

Conventions

Reader feedback

Customer support

Downloading the example code

Downloading the color images of this book

Errata

Piracy

Questions

Getting Started with Functional Programming in Swift

Why functional programming matters

What is FP?

The Swift programming language

Swift features

Modern syntax

Type safety and type inference

Immutability

Stateless programming

First-class functions

Higher-order functions

Closures

Subscripts

Pattern matching

Generics

Optional chaining

Extensions

Objective-C and Swift bridging headers

Automatic Reference Counting

REPL and Playground

Language basics

Types

Type inference

Type annotation

Type aliases

Type casting

Immutability

Tuples

Optionals

Basic operators

Strings and characters

Immutability

String literals

Empty Strings

Concatenating strings and characters

String interpolation

String comparison

Collections

Control flows

for loops

while loops

The stride functions

if

Switch

Guard

Functions

Closures

The map, filter, and reduce functions

The map function

The filter function

The reduce function

Enumerations

Generics

Classes and structures

Classes versus structures

Choosing between classes and structures

Identity operators

Properties

Property observers

Methods

Subscripts

Inheritance

Initialization

De-initialization

Automatic Reference Counting

Any and AnyObject

Nested types

Protocols

Protocols as types

Extensions

Protocol extensions

Access control

Error handling

Summary

Functions and Closures

What is a function?

Syntax

Best practices in function definition

Calling functions

Defining and using function parameters

Defining and using variadic functions

Returning values from functions

Defining and using nested functions

Pure functions

Function types

First-class functions

Higher-order functions

Function composition

Custom operators

Allowed operators

Custom operator definition

A composed function with custom operator

Closures

Closure syntax

Capturing values

Function currying

Recursion

Tail recursion

Memoization

Summary

Types and Type Casting

Kinds of types

Value versus reference types

Value and reference type constants

Mixing value and reference types

Copying

Copying reference types

Value type characteristics

Behaviour

Isolation

Interchangeability

Testability

Threats

Using value and reference types

Equality versus identity

Equatable and Comparable

Type checking and casting

Summary

Enumerations and Pattern Matching

Defining enumerations

Associated values

Raw values

Nesting and containing enumerations

Algebraic data types

Simple types

Composite types

Composite types with variants

The algebra of data types

Pattern matching

Patterns and pattern matching

The wildcard pattern

The value-binding pattern

The identifier pattern

The tuple pattern

The enumeration case pattern

The optional pattern

Type casting patterns

The expression pattern

Summary

Generics and Associated Type Protocols

What are Generics and what kind of problems do they solve?

Type constraints

The where clauses

Generic data structures

Associated type protocols

Type erasure

Extending Generic types

Subclassing Generic classes

Generics manifesto

Summary

Map, Filter, and Reduce

Higher-kinded types

Functors

Applicative Functors

Monads

The map function

The flatMap method

The filter function

The reduce function

The map function in terms of reduce

The filter function in terms of reduce

The flatMap function in terms of reduce

The flatten function in terms of reduce

The apply function

The join function

Chaining higher-order functions

The zip function

Practical examples

Sum and product of an array

Removing nil values from an array

Removing duplicates in an array

Partitioning an array

Summary

Dealing with Optionals

Optional types

Unwrapping optionals

Force unwrapping

nil checking

Optional binding

Guard

Implicitly-unwrapped optionals

Nil-coalescing

Optional chaining

Dealing with Optionals' functionally

Optional mapping

Multiple optional value mapping

Error handling

try!

try?

Summary

Functional Data Structures

Semigroups

Monoids

Trees

The contains method

Binary Search Trees

The contains method

Size

Elements

Empty

Lists

Empty LinkedList

Cons

Contains

Size

Elements

isEmpty

map, filter, and reduce

Stacks

Lazy lists

Summary

Importance of Immutability

Immutability

Immutable variables

Weak versus strong immutability

Reference types versus value types

Benefits of immutability

Thread safety

Referential transparency

Low coupling

Avoiding temporal coupling

Avoiding identity mutability

Failure atomicity

Parallelization

Exception handling and error management

Caching

State comparison

Compiler optimization

Cases for mutability

An example

Side-effects and unintended consequences

Testability

Copy constructors and lenses

Copy constructors

Lenses

Lens composition

Summary

Best of Both Worlds and Combining FP Paradigms with OOP

OOP paradigms

Objects

Classes

Inheritance

Overriding

Design constraints

Singleness

Static

Visibility

Composite reuse

Issues and alternatives

When to inherit

Polymorphism

Dynamic binding

OOP design principles

SRP

The FP counterpart

OCP

The FP counterpart

LSP

The FP counterpart

ISP

The FP counterpart

DIP

The FP counterpart

DDD

Concepts

Premise

Building blocks

Aggregate

Immutable value objects

Domain events

Intention-revealing interface

Side-effect-free functions

Assertions

Conceptual contours

Closure of operations

Declarative design

POP

POP paradigms

Protocol composition

Protocol extensions

Protocol inheritance

Associated types

Conforming to a protocol

Functional reactive programming

Building blocks of FRP

Events

Signals

Pipes

Signal producers

Observers

Lifetimes

Actions

Properties

Disposables

Schedulers

An example

Mixing OOP and FP

Problems

Granularity mismatch

FP paradigm availability

First-class values

Closures

FP-OOP interrelation tools

FP support

Effects of having FP capabilities in OOP

Idiomatic effects

Code abstraction at a function/method level

Generic iterator operations

Operation compositions and sequence comprehensions

Function partial applications and currying

Architectural effects

Reduction of the number of object/class definitions

Name abstraction at a function/method level

OOP design patterns - a FP perspective

Strategy pattern

Command pattern

Observer pattern

Virtual proxy pattern

Visitor pattern

Summary

Case Study - Developing an iOS Application with FP and OOP Paradigms

Requirements

High-level design

Frontend

Models

Views

ViewController

State

Store

Actions

Manager

Communication

Communication between layers

Third-party libraries/frameworks

Cross-cutting concerns

Error management and exception handling

Tools

Backend

Vapor

Routing

JSON

Request data

SPM

Backend development

Model

Store

Controller

Posting a new Todo item

Getting a list of Todo items

Getting a specific Todo item

Deleting an item and deleting all Todo items

Updating a Todo item

iOS application development

Configuration

Models

Operators

<^> operator

<*> operator

<| operator

<|? operator

<|| operator

Using Argo models

viewModel

Communication

The request protocol

Conforming to the request protocol

WebServiceManager

Creating a Todo item

Listing Todo items

Lenses

States

Store

Actions

Views

ViewControllers

MasterViewController

IBActions

TableView delegates and DataSource

DetailsViewController

Summary

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部