Tutorial
This tutorial builds a small, realistic project with byenull: a profile lookup. We start from a user directory full of nullable values, and end with a pipeline that finds a user, reads their optional profile, fetches their avatar, and produces either a guaranteed value or a typed failure, with every "maybe it's not there" handled once, at the source.
Each chapter adds one piece and shows its result. The chapters follow the shape of the library, so by the end you have used every function byenull has.
Basics
What an Option is, how to create one, and how to look inside safely.
- Option type: the
Some/Noneunion and the project we will build - Creating Options:
some,none,fn, andmaybe - Checking Options:
isSome,isNone, andisOption
Transforming
Composing lookups into pipelines that handle absence automatically.
- Pipe basics:
pipe, the heart of the library - Mapping Options: transforming values with
map - Chaining Options: sequencing lookups with
andThen - Recovering Options: fallbacks with
orElse - Inspecting Options: side effects with
inspectandinspectNone
Resolving
Ending a pipeline: getting a value out, or crossing into Results.
- Unwrapping Options: extracting values with
unwrap - Converting to Results:
toResultandfromResultwith @praha/byethrow
New to the library? Start with Why byenull? or jump straight into the first chapter.