How to Create a Sparse File

Sparse files are files with “holes”. File holes do not take up any physical space as the file system does not allocate any disk blocks for a hole until data is written into it. Reading a hole returns a null byte.

Virtual machine images are examples of spare files. For instance, when I create a VirtualBox machine and assign it a maximum storage of 100Gb, only the storage corresponding to the actual data in the machine is consumed.

Folding Things With Functional Programming

Folding things can be fun!

Introduction

In this post, we will discuss the concept of fold in functional programming: fold functions are used to reduce a data structure containing multiple values into a single one. Associated to the idea of fold are the concepts of...

  • recursion: via recursion, fold traverses the different elements of the data structure.
  • summarisation: the data structure with all its elements is reduced to a single value
You may also like: 10 Amazing Scala Collection Functions

In the following example, the class Rectangle can be reduced to a single value representing its area. However, it is not 'foldable' in the sense that there is no recursion involved.

Focus on Your Data Structures With Scala Lenses

With new programming techniques come new problems and new patterns to solve them.

In functional programming, immutability is a must. As a consequence, whenever it is needed to modify the content of a data structure, a new instance with updated values is created. Depending on how complex the data structure is, creating a copy may be a verbose task.