orchestrator 0.13.0 copy "orchestrator: ^0.13.0" to clipboard
orchestrator: ^0.13.0 copied to clipboard

Easily define complex code structures in Dart using many out-of-the-box elements.

example/main.dart

import 'package:orchestrator/orchestrator.dart';

void main() {
  // Example of a Fibonacci method.
  final element = Column([
    Method(
      name: 'fibonacci',
      returns: const TypeReference('int'),
      parameters: [
        const Parameter(
          name: 'n',
          type: TypeReference('int'),
        ),
      ],
      // Use [Column]s to add multiple elements within a body.
      body: Column([
        If(
          clauses: [
            IfClause(
              condition: or(
                const Static('n').equalTo(Literal.of(0)),
                const Static('n').equalTo(Literal.of(1)),
              ),
              body: const Static('n') //
                  .returned
                  .statement,
            ),
          ],
        ),
        const Static(''),
        // Builders can be used as top level functions...
        add(
          invoke(
            const Static('fibonacci'),
            // ...or on the [Element]'s themselves.
            [const Static('n').subtract(Literal.of(1))],
          ),
          invoke(
            const Static('fibonacci'),
            [const Static('n').subtract(Literal.of(2))],
          ),
        ).returned.statement,
      ]),
    ),
    const Static(''),
    const Static('result') //
        .declareVar
        .assign(const Static('fibonacci').invoke([Literal.of(20)]))
        .statement,
  ]);

  // Each element has their own [Emitter], this one can be used for (almost) all.
  const context = Context();
  const emitter = ElementEmitter(context);

  emitter.emit(element);
}
0
likes
0
pub points
0%
popularity

Publisher

verified publisheriruoy.nl

Easily define complex code structures in Dart using many out-of-the-box elements.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

collection, dart_style

More

Packages that depend on orchestrator