Skip to content

Commit

Permalink
Bridge: add itertools for partition_map
Browse files Browse the repository at this point in the history
OSS Review: itertools

This popular extension crate adds new methods for iterators.
Useful in this case as it cleans up a previous call to `fold()` designed
to partition a collection into 2 collections that can't be expressed
cleanly with a plain `partition()`.

The selected version is not the newest, but it aligns with a selected
version already included in the project transitively.
  • Loading branch information
svix-onelson committed Jul 10, 2024
1 parent c37fa72 commit 9070949
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
1 change: 1 addition & 0 deletions bridge/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions bridge/svix-bridge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ anyhow = "1"
clap = { version = "4.2.4", features = ["env", "derive"] }
axum = { version = "0.6", features = ["macros"] }
enum_dispatch = "0.3"
itertools = "0.12.1"
http = "0.2"
once_cell = "1.18.0"
opentelemetry = "0.22.0"
Expand Down
27 changes: 11 additions & 16 deletions bridge/svix-bridge/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{
};

use clap::Parser;
use itertools::{Either, Itertools};
use once_cell::sync::Lazy;
use opentelemetry_otlp::WithExportConfig;
use opentelemetry_sdk::{
Expand Down Expand Up @@ -361,22 +362,16 @@ async fn main() -> Result<()> {
if cfg.receivers.is_empty() {
tracing::warn!("No receivers configured.")
}
let (webhook_receivers, poller_receivers) = cfg.receivers.into_iter().fold(
(
Vec::<WebhookReceiverConfig>::new(),
Vec::<PollerReceiverConfig>::new(),
),
|mut acc, either| match either {
EitherReceiver::Webhook(x) => {
acc.0.push(x);
acc
}
EitherReceiver::Poller(y) => {
acc.1.push(y);
acc
}
},
);
let (webhook_receivers, poller_receivers): (
Vec<WebhookReceiverConfig>,
Vec<PollerReceiverConfig>,
) = cfg
.receivers
.into_iter()
.partition_map(|either| match either {
EitherReceiver::Webhook(x) => Either::Left(x),
EitherReceiver::Poller(y) => Either::Right(y),
});

let webhook_receivers_fut =
webhook_receiver::run(cfg.http_listen_address, webhook_receivers, xform_tx.clone());
Expand Down

0 comments on commit 9070949

Please sign in to comment.