/**
 * Given two sets of nested tuples containing species data, find and return the common species between them.
 *
 * @param nestedSpeciesTup1 A nested tuple containing species data.
 * @param nestedSpeciesTup2 A nested tuple containing species data.
 * @return A set containing common species.
 */
fun findCommonSpecies(nestedSpeciesTup1: List<Set<String>>, nestedSpeciesTup2: List<Set<String>>): Set<String> {

    val commonSpecies = mutableSetOf<String>()

    for (speciesSet1 in nestedSpeciesTup1) {
        for (speciesSet2 in nestedSpeciesTup2) {
            if (speciesSet1 is Set && speciesSet2 is Set) {
                commonSpecies.addAll(speciesSet1.intersect(speciesSet2))
            }
        }
    }

    return commonSpecies
}
/**
 * Given two sets of nested tuples containing species data, find and return the common species between them.
 *
 * @param nestedSpeciesTup1 A nested tuple containing species data.
 * @param nestedSpeciesTup2 A nested tuple containing species data.
 * @return A set containing common species.
 */
fun findCommonSpecies(nestedSpeciesTup1: List<Set<String>>, nestedSpeciesTup2: List<Set<String>>): Set<String> {
/**
 * Given two sets of nested tuples containing species data, find and return the common species between them.
 *
 * @param nestedSpeciesTup1 A nested tuple containing species data.
 * @param nestedSpeciesTup2 A nested tuple containing species data.
 * @return A set containing common species.
 */
fun findCommonSpecies(nestedSpeciesTup1: List<Set<String>>, nestedSpeciesTup2: List<Set<String>>): Set<String> {

    val commonSpecies = mutableSetOf<String>()

    for (speciesSet1 in nestedSpeciesTup1) {
        for (speciesSet2 in nestedSpeciesTup2) {
            if (speciesSet1 is Set && speciesSet2 is Set) {
                commonSpecies.addAll(speciesSet1.intersect(speciesSet2))
            }
        }
    }

    return commonSpecies
}