public function toArray(): array 
    {

        $to_array = function (EncapsulatedEdge $encapsulated): array {
            return $encapsulated->toArray();
        };

        $array = [];

        $array["to"] = [];
        foreach($this->to as $to => $encapsulated) {
            $array["to"][$to] = array_map($to_array, $encapsulated);
        }

        $array["from"] = [];
        foreach($this->from as $from => $encapsulated) {
            $array["from"][$from] = array_map($to_array, $encapsulated);
        }

        $array["in"] = array_map($to_array, $this->in);
        $array["out"] = array_map($to_array, $this->out);

        return $array;
    }