monadic 0.0.1

Monads for D


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

Monadic

API docs: https://katafrakt.github.io/monadic/

The goal of this repository if to probide a set of modules to work with common monads. It is based partly on Rust programming language, and partly on dry-monads for Ruby. So far it includes:

Monads:

  • Option

Wrappers:

  • JSON

Monads

Option

API docs: https://katafrakt.github.io/monadic/monadic/option.html

auto some = Some(4);
auto doubleMe = (int x) => x * 2;
auto result = some.map!doubleMe;
assert(!result.isNone());
assert(result.unwrap!int() == 8);

Wrappers

JSON

API docs: https://katafrakt.github.io/monadic/monadic/json.html

This is a wrapper on std.json to make querying JSONs easier. It is designed for programmers comfort, not for performance, and you should use it on schemaless JSONs. If you know the structure and want to map it into a struct, use asdf.

string s = `{ "language": "D", "applications": [{"name": "cool programming"}, {"name": "doing stuff", "examples": [1, 2, 3]}] }`;
auto mjson = parseJSON(s);
auto result = mjson.dig("applications", 0, "name");
assert(!result.isNone());
assert(result.unwrap!string() == "cool programming");
assert(result == Some("cool programming"));

result = mjson.dig("applications", 1, "examples", 1);
assert(result == Some(2));

result = mjson.dig("applications", 1, "examples", "test");
assert(result.isNone());
Authors:
  • katafrakt
Dependencies:
silly
Versions:
0.0.1 2022-Jun-21
~no-dual-context 2020-Aug-15
~main 2022-Jun-21
~gh-actions 2022-Jun-21
Show all 4 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 7 downloads total

Score:
0.4
Short URL:
monadic.dub.pm