Remove canonical link element from noindex pages

Not sure if there are any plugins out there that do this. But a simple function to remove the canonical URL like below seems to work based on my tests.

function wpse282643()
{
    global $post;

    // Check if WPSEO plugin is active and bail immediately if not (this is just a sample check)
    if ( ! defined( 'WPSEO_VERSION' ) ) {
        return;
    }

    // Check if current page/post has noindex set
    $noindex = \WPSEO_Meta::get_value( 'meta-robots-noindex', $post->ID );
    if ( '1' === $noindex ) {
        // Remove canonical URL
        remove_action( 'wpseo_head', [ \WPSEO_Frontend::get_instance(), 'canonical' ], 20 );
    }
}

add_action( 'template_redirect', 'wpse282643', 99 );