golo-lang/golo-lang — pull request #117 by k33g (2013-12-12 21:05:28+00:00)
Title: Add hasMethod to DynamicObject

Use case : verify if a method is define in a DynamicObject

Today, i've to do that :

let isImplemented = |method, object| {
let properties = object: properties(): filter(|property|-> property: getKey(): equals(method))
if properties: size(): equals(1) {
return isClosure(properties :iterator(): next(): getValue())
}
return false
}

let isObservable = |object| {
return isImplemented("attach", object) and isImplemented("notify", object)
}

Now i could write this :

let isObservable = |object| {
return object: hasMethod("attach") and object: hasMethod("notify")
}