Spec change - merge() function
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- javascript, typescript
- Área
- compilers
Línea de trabajo
Comienza con la sección de merge() de la especificación y la implementación propuesta en jmespath.ts. Determina si merge() debe aceptar objetos, arrays o un tipo restringido de array-of-objects, incluido el comportamiento documentado de los miembros del array. Se considera terminado cuando los ejemplos de la especificación y la firma e implementación en tiempo de ejecución de jmespath.ts coincidan con la semántica aceptada.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Background
In all the example given in the spec page for the merge() functionLITERAL types are provided as arguments to the function. While this demonstrates the behaviour it is not at all useful in practical terms. Literals can only be explicitly defined by the editor of an expression. Much more useful would be to merge on results of expressions or on projections.
Examples:
search([{a: "AY", x: "EX"}, {a: "EY", b: "BEE"}], 'merge(@)')
// OUTPUTS: {"a": "EY", "b": "BEE", "x": "EX"}
search([{a: "AY", x: "EX"}, {a: "EY", b: "BEE"}], 'merge([{FED: @[0].x}, {BAR: @[1].b}])')
// OUTPUTS: {"BAR": "BEE", "FED": "EX"}
In order to do this merge would have to accept either TYPE_OBJECT or TYPE_ARRAY to work and the function would need to be able to switch on either type to handle this.
Discussion
Array can contain any value and ideally we may want to restrict it to a new TYPE_ARRAY_OBJECT type so that we can guarantee only objects can be used in the merge. One interesting side effect of this in javascript is that merging arrays results in array members being keyed in their index. This means we can do the following with very little code change:
search([{"A": "ONE"}, "TWO", {"C": "THREE"}], 'merge(@)')
// OUTPUTS: {"0": "ZERO", "A": "ONE", "C": "THREE"}
// With all JSON array member types:
search([{"A": "ONE"}, true, null, "BAR", ["ZERO"], 666], 'merge(@)')
// OUTPUTS: {"0": "ZERO", "1": "A", "2": "R", "A": "ONE"}
Implementation in jmespath.ts
// Runtime
private functionMerge: RuntimeFunction<JSONObject[], JSONObject> = resolvedArgs => {
let merged = {};
for (let i = 0; i < resolvedArgs.length; i += 1) {
const current = resolvedArgs[i];
if (Array.isArray(current)) {
merged = Object.assign(merged, ...current);
} else {
merged = Object.assign(merged, current);
}
}
return merged;
};
// and in the function table
merge: {
_func: this.functionMerge,
_signature: [
{
types: [InputArgument.TYPE_OBJECT, InputArgument.TYPE_ARRAY],
variadic: true,
},
],
},
- Lenguaje dominante
- Python
- Estrellas
- 10
- Forks
- 3
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de jmespath/jmespath.jep
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 30/100
jmespath/jmespath.jep#36 ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
jmespath/jmespath.jep#35 ·
-
Root node accessAbierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
jmespath/jmespath.jep#34 · 1 comentario ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
jmespath/jmespath.jep#33 ·
-
Allow string comparisonAbierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
jmespath/jmespath.jep#32 ·
Todos los issues de jmespath/jmespath.jep
Issues similares
-
test_real_pandoc_failure_is_one_path_free_line fails on macOS CI with current Homebrew pandocAbiertobug TAG: unit tests
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
learningequality/ricecooker#898 ·
-
task
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
freelawproject/litigant-portal#1285 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
jmespath/jmespath.py#401 ·
-
least_squares returns a nonfinite objective for an invalid initial residualPosiblemente ocupada @sylvesterkaczmarek la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
google-deepmind/mujoco#4023 ·
Los mantenedores suelen responder en 11 días
-
Five Australian birds: Red-capped Parrot, Red-winged Fairywren, Gilbert’s Honeyeater, Western Spinebill, Western WattlebirdPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
arnegiacomo/fugleramme#427 ·
Los mantenedores suelen responder en 1 día