Skip to content

Instantly share code, notes, and snippets.

@Vova-SH
Created July 8, 2025 08:26
Show Gist options
  • Select an option

  • Save Vova-SH/9e3e6f5dd368bde6fd59fdcc3a2b1095 to your computer and use it in GitHub Desktop.

Select an option

Save Vova-SH/9e3e6f5dd368bde6fd59fdcc3a2b1095 to your computer and use it in GitHub Desktop.
DivKit get dict values
import com.yandex.div.evaluable.EvaluableType
import com.yandex.div.evaluable.EvaluationContext
import com.yandex.div.evaluable.ExpressionContext
import com.yandex.div.evaluable.Function
import com.yandex.div.evaluable.FunctionArgument
import org.json.JSONArray
import org.json.JSONObject
class GetDictValuesFunction : Function() {
override val name = "getOptDictValues"
override val declaredArgs = listOf(
FunctionArgument(type = EvaluableType.DICT), // variable name
)
override val resultType = EvaluableType.ARRAY
override val isPure = false
override fun evaluate(
evaluationContext: EvaluationContext,
expressionContext: ExpressionContext,
args: List<Any>
): Any {
val fallback = JSONArray()
val dict = args[0] as? JSONObject ?: return fallback
val result = JSONArray()
dict.keys().forEach { key ->
result.put(dict.get(key))
}
return result
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment