Book Image

Learning F# Functional Data Structures and Algorithms

By : Adnan Masood
Book Image

Learning F# Functional Data Structures and Algorithms

By: Adnan Masood

Overview of this book

Table of Contents (21 chapters)
Learning F# Functional Data Structures and Algorithms
Credits
Foreword
Foreword
Foreword
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Usage considerations for sequences


As seen earlier, sequences help solve problems in a functional manner by helping you avoid imperative constructs such as iterations and accumulators. However, sequences shouldn't be treated like silver bullets and must be used with good judgement, balancing performance and scalability. Recurring evaluation is a performance concern in sequences; even though on-demand evaluation is one of the powerful aspects of sequences, it may become a performance nightmare if you evaluate all the elements more than once. Depending on the sequence expression, you may end up paying a performance price for evaluating each element many times. In case you need to pre-calculate all the elements ahead of time, you can opt to use a different data structure or apply Seq.cache to the sequence.

Along with performance, a developer must also address the non-functional requirements of debugging, readability, and maintainability. Since sequences are evaluated in a lazy manner, it is...