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

Routers and Selectors. Part 3 match #805

Open
emil14 opened this issue Dec 14, 2024 · 0 comments
Open

Routers and Selectors. Part 3 match #805

emil14 opened this issue Dec 14, 2024 · 0 comments
Assignees

Comments

@emil14
Copy link
Collaborator

emil14 commented Dec 14, 2024

Previous parts:

Match

Basic

Match is a selector. It selects a message to send, but not the direction, so it has only one output port connected to its body.

data_sender -> match {
    cond_sender1: then_sender1
    cond_sender2: then_sender2
    ...
    _: default_sender
} -> receiver

Example

:number -> match {
    0: zero_string    // node that sends string
    1: one_string     // another node that sends string
    ...
    _: unknown_string // and one more string node
} -> :string

One might think that dictionary data type can handle this use-case. That's not entirely true because dictionary can't have network senders as keys and values

With Multiple Conditions On a Same Branch

Similar to if, match supports multiple condition senders on a single branch. Each condition sender is compared to the incoming data message in sequence before moving to the next branch. And of course it supports multiple receivers as a fan-out.

sender -> match {
    [cond_sender1, cond_sender2]: then_sender1
    ...
} -> [receiver1, receiver1]

Example

:binary -> match {
    [0, 1]: 'valid'
    _: 'not so valid'
} -> [log, db]

Match is blocked by its data sender, its branch then_senders and its receiver. The more parts it have the more it latency can be

As a Ternary

In the same way that switch can emulate if, match can emulate the ternary operator.

sender -> match {
    true: then_sender
    _: else_sender
} -> receiver

The ternary expression should be preferred whenever possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant