...

/

Handle Collections in Data Processing Applications

Handle Collections in Data Processing Applications

Apply functional programming to represent and handle collections in data processing applications.

There is an entrenched myth in the software industry that functional programming was invented by university researchers for “math stuff.” Functional programming is widely considered less relevant for real-world software applications, such as food delivery, ride-hailing, and e-commerce. More and more software engineers discover that functional programming is an elegant paradigm to solve many data processing problems in enterprise applications.

This lesson particularly looks into how functional programming allows us to elegantly handle collections of data commonly found in mobile and web applications or back-end services.

The map, filter, and fold functions are almost enough

Even though there are infinitely many problems to solve when processing data collections, most issues boil down to transforming, filtering, and accumulating data. Due to this, we combine map, filter, and fold to achieve most collection processing tasks.

To illustrate, let’s say we work on an e-commerce application where we need to handle products. In OCaml, we could use the record type to represent a product. For the sake of simplicity, we only consider the product’s name, type, and price.

type product_type = ELECTRONIC | BOOK | COSMETIC
type product = { name: string; product_type: product_type;
...