From 3f6cb919ac46e2af425558d863ec8e8d79e9e3e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Mon, 28 Mar 2022 17:40:04 +0200 Subject: [PATCH] connection-tester: extract or collection method --- .../validator-client/src/connection_tester.rs | 38 +++++++++---------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/common/client-libs/validator-client/src/connection_tester.rs b/common/client-libs/validator-client/src/connection_tester.rs index 0e1d51577a..390558d946 100644 --- a/common/client-libs/validator-client/src/connection_tester.rs +++ b/common/client-libs/validator-client/src/connection_tester.rs @@ -51,28 +51,24 @@ pub async fn run_validator_connection_test( .await; // Seperate and collect results into HashMaps - let (nymd_urls, api_urls) = { - ( - connection_results - .iter() - .filter(|c| c.url_type() == UrlType::Nymd) - .map(|c| { - let (network, url, result) = c.result(); - (*network, (url.clone(), *result)) - }) - .into_group_map(), - connection_results - .iter() - .filter(|c| c.url_type() == UrlType::Api) - .map(|c| { - let (network, url, result) = c.result(); - (*network, (url.clone(), *result)) - }) - .into_group_map(), - ) - }; + ( + extract_and_collect_results_into_map(&connection_results, &UrlType::Nymd), + extract_and_collect_results_into_map(&connection_results, &UrlType::Api), + ) +} - (nymd_urls, api_urls) +fn extract_and_collect_results_into_map( + connection_results: &[ConnectionResult], + url_type: &UrlType, +) -> HashMap> { + connection_results + .iter() + .filter(|c| &c.url_type() == url_type) + .map(|c| { + let (network, url, result) = c.result(); + (*network, (url.clone(), *result)) + }) + .into_group_map() } enum ClientForConnectionTest {