private function calculateUnion(Sequence $sequence, Period $period): Sequence
    {
        if ($sequence->isEmpty()) {
            $sequence->push($period);

            return $sequence;
        }

        $index = $sequence->count() - 1;
        $interval = $sequence->get($index);
        if ($interval->overlaps($period) || $interval->abuts($period)) {
            $sequence->set($index, $interval->merge($period));

            return $sequence;
        }

        $sequence->push($period);

        return $sequence;
    }
private function calculateUnion(Sequence $sequence, Period $period): Sequence
    {
        if ($sequence->isEmpty()) {
            $sequence->push($period);

            return $sequence;
        }

        $index = $sequence->count() - 1;
        $interval = $sequence->get($index);
        if ($interval->overlaps($period) || $interval->abuts($period)) {
            $sequence->set($index, $interval->merge($period));

            return $sequence;
        }

        $sequence->push($period);

        return $sequence;
    }
private function calculateUnion ( Sequence $ sequence , Period $ period ) : Sequence { if ( $ sequence -> isEmpty ( ) ) { $ sequence -> push ( $ period ) ; return $ sequence ; } $ index = $ sequence -> count ( ) - 1 ; $ interval = $ sequence -> get ( $ index ) ; if ( $ interval -> overlaps ( $ period ) || $ interval -> abuts ( $ period ) ) { $ sequence -> set ( $ index , $ interval -> merge ( $ period ) ) ; return $ sequence ; } $ sequence -> push ( $ period ) ; return $ sequence ; }
Iteratively calculate the union sequence.
Iteratively calculate the union sequence .