Need Help in understanding the scala function : i am completely new to scala programming and trying to understand a function written (functional programming )by our architect. can someone please help me in understanding this logic.

    def checkS3BValidity(rows: Vector[Map[String, Object]]): Vector[Map[String, Object]] = {
    
    val s3 = List("app_code", "s3_access_key", "s3_secret_key", "s3_primary_bkt_name")
    val excludeList = new ListBuffer[String]
    for (elem <- rows map (row => s3 map row)) {
      val elem_str = elem.map(_.toString)
      logger.info("verifying the S3 bucket passed from the ctrl table for each App")
      logger.info(s"Checking on App Code: ${elem head}")
     listS3Buckets(elem_str(1), elem_str(2)) match {
        case Some(allBktsInfo) =>
          logger.info(s"App: ${elem_str head} provided the bucket name as: ${elem_str(3)}")
          if (allBktsInfo.exists(x => x.getName == elem_str(3))) {
            logger.info(s"Provided S3 bucket: ${elem_str(3)} exists")
            println(s"s3 ${elem_str(3)} bucket exists")
          } else {
            logger.info(s"WARNING: Provided S3 bucket ${elem_str(3)} doesn't exists")
            logger.info(s"WARNING: Dropping the App: ${elem_str.head} from backup schedule")
            excludeList += elem_str.head // If the bucket is invalid then we exclude from backup
            println(s"s3 bucket ${elem_str(3)} doesn't exists")
        }
        case None =>
          logger.info(s"WARNING: Provided S3 bucket ${elem_str(3)} doesn't exists")
          logger.info(s"WARNING: Dropping the App: ${elem_str.head} from backup schedule")
          excludeList += elem_str.head // If the bucket is invalid then we exclude from backup
    }
     logger.info(s"WARNING: Couldn't access these buckets: $excludeList")
    rows filterNot (row => row.exists(m => excludeList.contains(m._2)))
    
      }