2
\$\begingroup\$

Jenkins DSL doesn't support collect and inject from what I can tell (I get missing method exceptions when I try), so I implemented my own map & reduce functions to use. I'm not sure if there's much to say about this small snippet of code, but I'd love to hear from some groovy or FP folks.

def map = { collection, f ->
  def result = []
  collection.each { element ->
    result.add(f(element))
  }
  result
}

def reduce = { collection, accumulator, f ->
  def result = accumulator
  collection.each { element ->
    result = f(result, element)
  }
  result
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.