Parámetro de desestructuración de una función Clojure manteniendo el valor original.


¿Puede usted desestructurar un parámetro de función pero todavía tiene el original disponible para su uso? La forma en que lo estoy haciendo ahora es solo usando una forma let dentro del cuerpo de la función, pero me pregunto si había una forma más concisa de hacerlo.

Author: noahlz, 2012-09-25

1 answers

Parece que :as también funciona para funciones:

Con vector

(defn test [[x y :as v]]
  {:x x :y y :v v})

(test [1 2 3 4])
=>  {:x 1 :y 2 :v [1 2 3 4]}

Con hash-map

(defn test2 [{x :x y :y :as m}]
    {:x x :y y :m m})

(test2 {:x 1 :y 2 :z 3})
=> {:x 1 :y 2 :m {:x 1 :y 2 :z 3}}

Ver esta excelente entrada de blog: http://blog.jayfields.com/2010/07/clojure-destructuring.html

 25
Author: noahlz,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-09-25 02:35:44