다음은 args라는 가상의 해시 맵입니다.
{:body {:milestones [{:status 1 :otherValues x}
{:status 2 :otherValues z}
{:status 1 :otherValues y]}}
내 목표는 각 : status 키에 대한 값 모음을 갖는 것입니다. 그들은 모두 : milestones의 자식과 같은 깊이에 있습니다.
가까워지고 있습니다. 다음을 수행하여 첫 번째 상태의 값을 검색하는 방법을 알고 있습니다.
(let [{[{:keys [status]} x] :milestones} :body} args]
(println status))
파 엔드 목표는 값이 1 인 : status가 포함 된 맵을 찾고 각 개별 맵으로 새 컬렉션을 만드는 것입니다.
문자 그대로 TeamworkPM에 연결하고 "늦음"또는 "불완전"상태의 마일스톤을 Google 캘린더와 동기화하는 것입니다.
이 시나리오에서 원하는 출력은 {1, 2, 1}입니다. 최종 목표는
{{:status 1 :otherValues x}
{:status 1 :otherValues Y}}
맵의 벡터를 변수로 직접 분해하는 방법을 찾을 수는 없지만 먼저 자식을 :milestones
가져온 다음 기본 map
또는 filter
.
map을 함수로 적용하여 값을 얻을 수 있습니다. (예를 들어 경우 m
이다 {:key1 "val1"}
, (m :key1)
것 "val1"
)
(def args {:body {:milestones [{:status 1 :otherValues 'x}
{:status 2 :otherValues 'z}
{:status 1 :otherValues 'y}]}})
(let [{{x :milestones} :body} args,
y (map #(% :status) x),
z (filter #(= (% :status) 1) x)
]
(println x) ; [{:status 1, :otherValues x} {:status 2, :otherValues z} {:status 1, :otherValues y}]
(println y) ; (1 2 1)
(println z) ; ({:status 1, :otherValues x} {:status 1, :otherValues y})
)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다