tag 1.0.0

Add "tagged value" to D for an effective use of std.variant.Algebraic.


To use this package, put the following dependency into your project's dependencies section:

dub.json
dub.sdl

tag

Introdubtion

Add "tagged value" to D for an effective use of std.variant.Algebraic.

Example

import tag;
import std.variant : Algebraic, visit;

/// optional type definition
alias Option(T) = Algebraic!(
  Tag!("Some", T),
  Tag!"None"
);

void main() {
  Option!int option;
  
  option = tag!"Some"(1);
  f(option).writeln; // 2
  
  option = tag!"None";
  f(option).writeln; // -1
}

int f(Option!int opt) {
  /// pattern mathing
  return opt.visit!(
    (Tag!("Some", int) a) => a + 1,
    (Tag!"None" a) => -1;
  );
}

Document

Authors:tosuke

Dependencies: none

Versions:
1.0.0 2017-Jul-31
~master 2017-Jul-31
Show all 2 versions
Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 0 downloads total