Skip to content

Expose CheckCycle API #25

@Niels-Be

Description

@Niels-Be

Hello,

In my use case I construct a graph to validate a user input. When the input changes I modify the graph accordingly. One of the validations is to check for cycles in the graph.

My current solutions is:

function checkCycle() {
    this.graph.circular = false;
    let res = null;
    try {
        this.graph.overallOrder();
    } catch(e) {
        res = e.message;
    }
    this.graph.circular = true;
    return res;
}

But I this is bad in multiple ways.

  1. First of all it modifies the internal circular property temporary. (not exposed to Typescript)
  2. It does unnecessary work, since the result of overallOrder() is not used.
  3. Relying on exceptions is not clean code.
  4. This might suppress other errors.

In my opinion checking for cycles is a general use case and it would be nice if the library can expose it as a function.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions