Functional C# uncover the secrets of functional programming using C# and change the way you approach your applications forever
Uncover the secrets of functional programming using C# and change the way you approach your applications forever About This Book This book focuses on the functional paradigm of C#, which will give you a whole new angle on coding with C# It illustrates the advantages that functional programming bring...
Otros Autores: | |
---|---|
Formato: | Libro electrónico |
Idioma: | Inglés |
Publicado: |
Birmingham, England ; Mumbai, [India] :
Packt
2016.
|
Edición: | 1st edition |
Materias: | |
Ver en Biblioteca Universitat Ramon Llull: | https://discovery.url.edu/permalink/34CSUC_URL/1im36ta/alma991009630327206719 |
Tabla de Contenidos:
- Cover
- Copyright
- Credits
- About the Author
- Acknowledgments
- About the Reviewer
- www.PacktPub.com
- Customer Feedback
- Table of Contents
- Preface
- Chapter 1: Tasting Functional Style in C#
- Introducing functional programming
- Understanding definitions, scripts, and sessions
- Using substitution and simplification to evaluate the expression
- Understanding the functions used for functional programming
- Forming the definition
- Currying
- Comparison between functional and imperative programming
- Preparing the C# compiler
- Concepts of functional programming
- First-class and higher-order functions
- Function types
- Function values
- Pure functions
- Recursive functions
- Feeling functional in C#
- Using mathematical concept to understand functional approach
- Applying tuple for functional C#
- Currying in C#
- Pipelining
- Method chaining
- Transforming imperative code to functional code
- The imperative code approach
- The functional code approach
- The GenerateOrderedList() method
- The Main() method
- The advantages and disadvantages of functional programming
- Summary
- Chapter 2: Walkthrough Delegates
- Introducing delegates
- Simple delegates
- Multicast delegates
- Using the Delegate.Combine() and Delegate.Remove() methods
- Using += and -= operators
- Built-in delegates
- Generic delegates
- The Action and Func delegates
- Distinguishing variance in delegates
- Covariance
- Contravariance
- Summary
- Chapter 3: Expressing Anonymous Methods with Lambda Expressions
- Getting to know anonymous methods
- Creating anonymous methods
- Using an anonymous method as an argument
- Writing anonymous methods - some guidelines
- Advantages of the anonymous methods
- Lambda expressions
- Transforming an anonymous method to a lambda expression.
- Creating a delegate type using lambda expresions
- Expression trees and lambda expressions
- Subscribing for events using lambda expressions
- Using the event keyword
- Using EventHandler or EventHandler<
- T>
- The advantages of using lambda expression in functional programming
- First-class functions
- Closure
- Summary
- Chapter 4: Extending Object Functionality with Extension Methods
- Getting closer to extension methods
- Creating an extension method
- Extension methods in the code IntelliSense
- Calling extension methods in the other assemblies
- Referencing a namespace
- Piggybacking a namespace
- Leveraging the interface, collection, and object
- Extending the interface
- Extending the collection
- Extending an object
- Advantages of using extension methods in functional programming
- Limitations of the extension method
- Extending a static class
- Modifying the method implementation in the existing class or type
- Summary
- Chapter 5: Querying Any Collection Easily with LINQ
- Getting started with LINQ
- Deferring LINQ execution
- Choosing between fluent syntax and query expression syntax
- Understanding the LINQ fluent syntax
- Understanding the LINQ query expression syntax
- Enumerating standard query operators
- Filtering
- Projection
- Joining
- Ordering
- Grouping
- The set operation
- Conversion methods
- Element operation
- Summary
- Chapter 6: Enhancing the Responsiveness of the Functional Program with Asynchronous Programming
- Building a responsive application
- Running a program synchronously
- Applying threads in the program
- Creating threads using thread pool
- The asynchronous programming model pattern
- Using the synchronous Read() method
- Using the BeginRead() and EndRead() methods
- Adding LINQ to the BeginRead() method invocation.
- The task-based asynchronous pattern
- Introducing the Task and Task<
- TResult>
- classes
- Applying a simple TAP model
- Using the WhenAll() extension method
- Wrapping an APM into a TAP model
- Asynchronous programming with the async and await keywords
- Asynchronous functions in functional programming
- Summary
- Chapter 7: Learning Recursion
- Exploring recursion
- Working of the recursive routine
- Refactoring an iteration to the recursion
- Using tail recursion
- Accumulator-passing style
- Continuation-passing style
- Indirect recursion over direct recursion
- Recursion in a functional approach using LINQ Aggregate
- Delving into the Aggregate method
- Summary
- Chapter 8: Optimizing the Code using Laziness and Caching Techniques
- Introduction to laziness
- Lazy enumeration
- Lazy evaluation
- Nonstrict evaluation
- Lazy initialization
- The advantages and disadvantages of being lazy
- Caching expensive resources
- Performing initial computation
- Memoization
- Summary
- Chapter 9: Working with Pattern
- Dissecting pattern matching in functional programming
- Transforming data using pattern matching
- Switching for pattern matching
- Simplifying pattern matching
- Welcoming the coming of pattern matching feature in C# 7
- Introducing Monad as a design pattern
- Creating the Monadic M<
- T>
- type
- Implementing the generic data type to Monad
- Implementing Monad to Lazy<
- T>
- and Task<
- T>
- Rules of the Monad pattern
- Summary
- Chapter 10: Taking an Action in C# Functional Programming
- Developing functional programming in Windows forms
- Creating the code behind a form
- Creating the engine code in an imperative approach
- Preparing class properties
- Constructing the constructor
- Clearing the properties
- Appending the number to the display box.
- Preparing the mathematical operation
- Formatting the input
- Solving the calculation
- Calculating the additional operation
- Creating the engine code in the functional approach
- Adding several new properties
- Simplifying the pattern matching
- Assigning the properties
- Constructing the class by clearing the properties
- Appending the inputted number to the text box
- Preparing the operation
- Formatting the input
- Solving the calculation
- Calculating the additional operation
- Summary
- Chapter 11: Coding Best Practice and Testing the Functional Code
- Coding best practices in functional C#
- Preventing dishonest signatures
- Refactoring a mutable class into an immutable one
- Avoiding mutability and temporal coupling
- Dealing with the side-effects
- Separating the code from domain logic and mutable shell
- Examining the code containing side-effects
- Refactoring the AddRecord() method
- Refactoring the RemoveRecord() method
- Running domain logic in unit testing
- Testing the AddRecord() method
- Testing the RemoveRecord() method
- Executing the test
- Adding the mutable shell into code
- Summary
- Index.