maybe

basic monadic maybe type for Nim

Pure Nim score 15/100 · tests present · no docs generated

Summary

Latest Version Unknown
License BSD3
CI Status Failing
Downloads 0
Last Indexed 2026-07-21 05:23

Installation

nimble install maybe
choosenim install maybe
git clone https://github.com/superfunc/maybe

OS Compatibility

Platform Linux macOS Windows FreeBSD OpenBSD NetBSD Android iOS WASM Embedded
maybe - - - - - - -

Source

Repository https://github.com/superfunc/maybe
Homepage https://github.com/superfunc/maybe
Registry Source nimble_official

README

maybe

Build status badge

Nimble Package: https://nimble.directory/pkg/maybe

Docs: https://superfunc.github.io/maybe

Note 1: ~There is a chance the main macro(maybeCase) may get merged into the standard library. If this happens I'll recommend people use that, but will accept bugfixes and reports on this library going forward, just no new features.~

Note 2: The PR was not accepted, so maybe lives on!

An implementation of a maybe type, also known as option(al) in other languages.

Why Not Just use Option[T] from the standard library?: In short, this library doesn't throw exceptions. It achieves this by using a macro to provide a safe pattern in which a maybe object can't be invalidly accessed, see maybeCase in the docs for further details. For a small example:

var m = maybe.just(4)
maybeCase m:
  just x:
    var y = 3
    echo $(x+y)
  nothing:
    echo "no value"

var nada = maybe.nothing[int]()
maybeCase nada:
  just foo:
    echo "hi this is a value we cant print" & $foo
  nothing:
    echo "nope no value, nice try with your invalid access"

## This prints out:
## >> 7
## >> nope no value, nice try with your invalid access

Note that trying to access our local binding(x and foo) outside of the just blocks will result in a compile time error. This is how we achieve safe access.

Installation

Should be installed via nimble

nimble install maybe

License Info

Copyright (c) Josh Filstrup 2014-2019 Licensed under BSD3 (see license.md for details)