I am a Groovy beginner
These are two each calls which both do a similar task but with a different property of s2PublicLifecycleInstance.
How can I write a separate function which does the following, so that I can have only method call to achive the task?
def scheduledStatusArray =[]
def publishedStatusArray =[]
s2PublicLifecycleInstance.each {
if(it.scheduledInMyLearnStatus == "No"){
scheduledStatusArray.add(1)
} else if(it.scheduledInMyLearnStatus == "Yes"){
scheduledStatusArray.add(2)
}else{
scheduledStatusArray.add(3)
}
}
s2PublicLifecycleInstance.each {
if(it.publishedOnTrainingClassesStatus == "No"){
publishedStatusArray.add(1)
}else if(it.publishedOnTrainingClassesStatus == "Yes"){
publishedStatusArray.add(2)
}else{
publishedStatusArray.add(3)
}
}
I want something like this:
def publishedStatusArray = functionCall(s2PublicLifecycleInstance, propertyName)
is it possible in Groovy?
I agree with gasan. I can add, that
def publishedStatusArray = functionCall(s2PublicLifecycleInstance, propertyName)is possible in groovy. The function:
will return the property you want.