Optional Library 0.1
A general-purpose Maybe type for C
Loading...
Searching...
No Matches
Optional Library

Optional Library

Introduction

A general-purpose Maybe type for representing missing values in C without NULL or sentinel values.

Note
Schrödinger's cat is inside a box. Until you look, you don't know if it's alive or dead. A Maybe type works the same way. It either contains a cat, meaning you have a value, or it's empty, meaning you have nothing. Instead of risking errors when there's no cat, OPTIONAL makes you handle both cases explicitly, eliminating the need for null checks or sentinel values.

Getting Started

Adding Optionals to Your Project

This library consists of one header file only. All you need to do is copy optional.h into your project, and include it.

#include <optional.h>
A general-purpose Maybe type for C.

Since it's a header-only library, there is no library code to link against.

Remarks
Optionals are useful for representing values that may or may not be present. To indicate why a value is absent, you may want to use Results instead.

Optional Types and Variables

Creating Optional Objects

Basic Usage

Checking for Presence

Unwrapping Values

Conditional Actions

Advanced Usage

Screening Optionals

Transforming Values

Additional Info

Compatibility

Optionals rely on modern C features such as designated initializers, compound literals, and typeof.

Releases

This library adheres to Semantic Versioning. All notable changes for each version are documented in a change log.

Head over to GitHub for the latest release.

Latest Release

Source Code

The source code is available on GitHub.

Fork me on GitHub