All Projects β†’ werediver β†’ sum_types.dart

werediver / sum_types.dart

Licence: MIT license
A code generator enabling sum-types in Dart

Programming Languages

dart
5743 projects
shell
77523 projects

Projects that are alternatives of or similar to sum types.dart

dotvariant
A type-safe and space-efficient sum type for C# (comparable to discriminated unions in C or C++)
Stars: ✭ 52 (+33.33%)
Mutual labels:  algebraic-data-types, sum-types
Swift Enum Properties
🀝 Struct and enum data access in harmony.
Stars: ✭ 191 (+389.74%)
Mutual labels:  algebraic-data-types, code-generation
mr.boilerplate
Online app to generate Scala boilerplate
Stars: ✭ 32 (-17.95%)
Mutual labels:  code-generation
go-inline
Generic Data Structures/Algorithms in golang.
Stars: ✭ 52 (+33.33%)
Mutual labels:  code-generation
pystella
A code generator for grid-based PDE solving on CPUs and GPUs
Stars: ✭ 18 (-53.85%)
Mutual labels:  code-generation
laboratory
Feature flags for multi-module Kotlin Android projects
Stars: ✭ 71 (+82.05%)
Mutual labels:  code-generation
EMF
Extended Mechanics & Flavor
Stars: ✭ 33 (-15.38%)
Mutual labels:  code-generation
mutoid
Reactive library for data fetching, caching, state management
Stars: ✭ 24 (-38.46%)
Mutual labels:  algebraic-data-types
bitty
πŸ—ƒ A mono-repository with functional programming helpers, algebraic data types, util functions, types and even some micro frameworks in TypeScript.
Stars: ✭ 27 (-30.77%)
Mutual labels:  algebraic-data-types
jeta
brooth.github.io/jeta
Stars: ✭ 21 (-46.15%)
Mutual labels:  code-generation
enumer
A Go tool to auto generate methods for your enums
Stars: ✭ 167 (+328.21%)
Mutual labels:  code-generation
PyRates
Open-source, graph-based Python code generator and analysis toolbox for dynamical systems (pre-implemented and custom models). Most pre-implemented models belong to the family of neural population models.
Stars: ✭ 33 (-15.38%)
Mutual labels:  code-generation
create-graphql-app
Cli tool for bootstrapping serverless GraphQL api
Stars: ✭ 28 (-28.21%)
Mutual labels:  code-generation
vallang
Generic immutable recursive data representation API targeted at source code models and more.
Stars: ✭ 28 (-28.21%)
Mutual labels:  algebraic-data-types
LinqToXsdCore
LinqToXsd ported to .NET Core (targets .NET Standard 2 for generated code and .NET Core 3.1, .NET 5+ 6 for the code generator CLI tool).
Stars: ✭ 23 (-41.03%)
Mutual labels:  code-generation
overture
The Overture Tool
Stars: ✭ 45 (+15.38%)
Mutual labels:  code-generation
Rosalina
Rosalina is a code generation tool for Unity's UI documents. It generates C# code-behind script based on a UXML template.
Stars: ✭ 57 (+46.15%)
Mutual labels:  code-generation
LstGen
Code-Generator fΓΌr die Lohnsteuerberechnung aus PAP XML
Stars: ✭ 19 (-51.28%)
Mutual labels:  code-generation
libgen
Automatic C-bindings generator for the Crystal language
Stars: ✭ 71 (+82.05%)
Mutual labels:  code-generation
dart meta types
a code gen solution for defining sealed classes, data classes, and enum classes for dart.
Stars: ✭ 25 (-35.9%)
Mutual labels:  algebraic-data-types

Build Status sum_types version sum_types_generator version

sum_types and sum_types_generator

sum_types and sum_types_generator packages together define a code generator enabling sum-types in Dart.

NOTE: v0.2.0 is a major update with backward-incompatible changes.

Example

In example/lib/src/ you can find a few sum-type declarations and the code generated for them.

This one models the natural numbers (with zero):

import 'package:meta/meta.dart';
import 'package:sum_types/sum_types.dart';

@SumType()
class Nat extends _$Nat {
  const Nat.zero() : super(zero: const Unit());
  const Nat.next(Nat value) : super(next: value);

  Nat operator +(Nat other) => this.iswitch(
        zero: () => other,
        next: (next) => Nat.next(next + other),
      );

  int toInt() => this.iswitch(
        zero: () => 0,
        next: (next) => 1 + next.toInt(),
      );
}

Features

Core:

  • Const case-constructors (const Nat.zero())
  • Extensible sum-types (Nat.toInt())
  • Nested sum-types
  • Recursive sum-types (Case<_Nat>(name: "next") β†’ Nat.next(Nat.zero()))
  • Generic sum-types (Either<Left, Right>)
  • Exhaustive in-line iswitch
  • Inexhaustive in-line iswitcho (with otherwise: case)

Sugar:

  • No-payload cases (Case<void>(name: "zero") β†’ Nat.zero())
  • Default case-names (Case<String>() β†’ JSON.string("some"))

Trivia:

  • Equality test
  • Hash function
  • To string conversion

Serialization-deserialization support through product-types interoperability:

  • Deserialization support (NatRecord<Self>, Nat.load<T extends NatRecord<T>>(T rec))
  • Serialization support (Nat.dump<T>(T Function({Unit zero, T next} make)))

Development

Find the upcoming development plans in the project planner.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].