Created
July 8, 2025 08:26
-
-
Save Vova-SH/9e3e6f5dd368bde6fd59fdcc3a2b1095 to your computer and use it in GitHub Desktop.
DivKit get dict values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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