https://github.com/foxcapades/d-lib-option
https://github.com/foxcapades/d-lib-option
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/foxcapades/d-lib-option
- Owner: Foxcapades
- License: mit
- Created: 2019-03-28T15:34:43.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-07-18T18:27:58.000Z (about 7 years ago)
- Last Synced: 2025-04-06T11:48:41.558Z (over 1 year ago)
- Language: D
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.adoc
- License: LICENSE
Awesome Lists containing this project
README
= Options for D!
Exciting!
Comes in 2 flavors!
Definitely done before!
Truly astonishing!
== Q&A
=== What is this?
A small minded implementation of option types in D.
=== Why not just use ?
You should definitely use .
=== Will it finally allow me to download a car?
It absolutely will, yes.
== Use the things
=== `option(T)` struct form for when you want structs
[source, d]
----
auto foo = none!int;
auto bar = some(3);
auto fizz = maybe!(int*)(null);
auto buzz = some!(int*)(null); // ERROR
----
=== `Option(T)` class form for when you want classes
[source, d]
----
auto foo = Options.none!int();
auto bar = Options.some(3);
auto fizz = Options.maybe!(int*)(null);
auto buzz = Options.some!(int*)(null); // ERROR
----
=== `==` and `!=` Overload for when you want to use `==` or `!=`
[source, d]
----
auto noneA = none!int;
auto noneB = none!int;
auto some2a = some!int(2);
auto some2b = some!int(2);
auto some3 = some!int(3);
assert(noneA == noneB);
assert(noneA != some3);
assert(some2a == some2b);
assert(some2a != some3);
----