12 Understanding Julia collections

 

This chapter covers

  • Understanding how collections are categorized according to the type of operations they support
  • Turning staged rockets into an iterable collection
  • Using common operations supported by various collection types

You have already looked at collections such as arrays and dictionaries, but there are many other types of collections, including sets, linked lists, heaps, stacks, and binary trees. In this chapter, I will cover the commonalities between different types of collections. Every collection organizes and stores multiple elements, and each collection type offers unique ways of accessing these elements. For example, with a dictionary, you can access elements by providing a key, while an array requires an index.

However, collections also have core functionality that all collections must support, such as being iterable. If something is iterable, you can access the individual elements in a for loop or use a higher-order function, such as map or filter.

What exactly makes something a collection? What are the differences and similarities between different collection types? And how can you make your own? You will explore these questions by expanding on the multistage rocket example from chapter 8. Because the rocket is made up of many different parts, it is possible to turn it into something Julia will recognize as a collection.

12.1 Defining interfaces

12.2 Propellant tank interface example

12.3 Interfaces by convention

12.4 Implementing engine cluster iteration

12.4.1 Making clusters iterable

12.5 Implementing rocket stage iteration

12.5.1 Adding support for map and collect

12.6 Comparison of linked lists and arrays

12.6.1 Adding and removing elements

12.7 Utility of custom types

Summary