Filter by month within a structure

Hey there,

I have a simple structure field with some events which contain a startdate, enddate and a title.

My desired output is (for all months in the year)

--- (only show section if month has an event)
Monthname 
Startdate | Enddate | Event
Startdate | Enddate | Event
Startdate | Enddate | Event

--- (only show section if month has an event)
Monthname 
Startdate | Enddate | Event
Startdate | Enddate | Event
Startdate | Enddate | Event

I wanted to filter by month to loop through them but I cant get $data->events()->toStructure()->filterBy() to work with ANYthing. Is this even possible? Can someone push me in the right direction?

Thank you very much.

Something along these lines:

$events = $data->events()
               ->toStructure()
               ->map(function($event) {
                 return [
                   'month'     => $event->date('F Y', 'startdate'), // for "January 2017" as an example
                   'startdate' => $event->startdate(),
                   'enddate'   => $event->enddate(),
                   'title'     => $event->title(),
                 ];
               })->groupBy('month');

dump() the $events variable to see the result.