title: How to write Spark UDF which takes Array[StructType], StructType as input and return Array[StructType]
body: <p>I have a DataFrame with the following schema :</p>
  <pre><code>root
   |-- user_id: string (nullable = true)
   |-- user_loans_arr: array (nullable = true)
   |    |-- element: struct (containsNull = true)
   |    |    |-- loan_date: string (nullable = true)
   |    |    |-- loan_amount: string (nullable = true)
   |-- new_loan: struct (nullable = true)
   |    |-- loan_date : string (nullable = true)
   |    |-- loan_amount : string (nullable = true)
  
  </code></pre>
  <p>I want to use a UDF, which takes <strong>user_loans_arr</strong> and <strong>new_loan</strong> as inputs and add the new_loan struct to the existing user_loans_arr. Then, from user_loans_arr delete all the elements whose loan_date is older than 12 months.</p>
  <p>Thanks in advance.</p>