Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add combinators for blocks #69

Closed
bytesnake opened this issue Oct 4, 2022 · 3 comments
Closed

Add combinators for blocks #69

bytesnake opened this issue Oct 4, 2022 · 3 comments

Comments

@bytesnake
Copy link

It would be great to have combinators (similar to Iterator's map, filter, join, reduce etc.) available for all blocks doing sample or message processing. Normally they are implemented using a trait similar to https://doc.rust-lang.org/std/iter/trait.Iterator.html

@bastibl
Copy link
Member

bastibl commented Oct 4, 2022

We already have functional-style blocks (map -> Apply, filter -> Filter, etc). See the top here. But, at the same time, an SDR is not an Iterator and it is not immediately clear how this could be done. Any concrete suggestions? PRs are very welcome!

@bytesnake
Copy link
Author

to give a concrete example, you can compose types implementing a trait (for async you have the Stream trait as example):

let block = FileSource::<Complex<f32>>::new("my_filename.cf32", false)
    .map(|sample| sample * 0.5)
    .filter(|sample| sample.abs() < 0.5)
    .join(second_file);

let source = fg.add_block(block);

@bastibl
Copy link
Member

bastibl commented Oct 4, 2022

At the moment, this would be something like:

let block = FileSource::<Complex32>::new("my_filename.cf32", false);
let map = Apply::new(|s: &Complex32| s * 0.5);
let filter = Filter::new(|s: &Complex32| if s.abs() < 0.5 { Some(*s) } else { None });

connect!(fg, block > map > filter > second_file);

I think this is fine, since the whole point is really to have multiple blocks. At least, this is what has to happen under the hood. Not sure, if it is desired to fake this abstraction. If you want to chain iterators within one block, this could be done with the Iterator block. Then you have file source -> chained iterators in one iterator block -> file sink

@bastibl bastibl closed this as completed Nov 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants