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

Core: revamp Choices Java DSL for doSwitch and randomSwitch #4492

Closed
slandelle opened this issue Dec 8, 2023 · 0 comments
Closed

Core: revamp Choices Java DSL for doSwitch and randomSwitch #4492

slandelle opened this issue Dec 8, 2023 · 0 comments

Comments

@slandelle
Copy link
Member

With the latest changes, we can write:

doSwitch()
  .on(
    Choice.withKey("key1", chain1, chain2, chain3),
    Choice.withKey(key2", chain4, chain5),
  )

randomSwitch()
  .on(
    Choice.withWeight(double1, chain1, chain2, chain3),
    Choice.withWeight(double2, chain4, chain5),
  )

This doesn't format nicely, in particular when chains are not references but inline.
We should separate the key and weight from the chains.

doSwitch()
  .on(
    onCase("key1").then(chain1, chain2, chain3),
    onCase(key2").then(chain4, chain5),
  )

randomSwitch()
  .on(
    withWeight(double1).then(chain1, chain2, chain3),
    withWeight(double2).then(chain4, chain5),
  )
@slandelle slandelle added this to the 3.10.0 milestone Dec 8, 2023
@slandelle slandelle self-assigned this Dec 8, 2023
slandelle added a commit that referenced this issue Dec 8, 2023


Motivation:

With the latest changes, we can write:

```java
doSwitch()
  .on(
    Choice.withKey("key1", chain1, chain2, chain3),
    Choice.withKey(key2", chain4, chain5),
  )

randomSwitch()
  .on(
    Choice.withWeight(double1, chain1, chain2, chain3),
    Choice.withWeight(double2, chain4, chain5),
  )
```

This doesn't format nicely, in particular when chains are not references but inline.

Modifications:

We should separate the key and weight from the chains.

```java
doSwitch()
  .on(
    onCase("key1").then(chain1, chain2, chain3),
    onCase(key2").then(chain4, chain5),
  )

randomSwitch()
  .on(
    withWeight(double1).then(chain1, chain2, chain3),
    withWeight(double2).then(chain4, chain5),
  )
```

The existing Choice static factories are deprecated and will be removed in the next release.
slandelle added a commit that referenced this issue Dec 8, 2023


Motivation:

With the latest changes, we can write:

```java
doSwitch()
  .on(
    Choice.withKey("key1", chain1, chain2, chain3),
    Choice.withKey(key2", chain4, chain5),
  )

randomSwitch()
  .on(
    Choice.withWeight(double1, chain1, chain2, chain3),
    Choice.withWeight(double2, chain4, chain5),
  )
```

This doesn't format nicely, in particular when chains are not references but inline.

Modifications:

We should separate the key and weight from the chains.

```java
doSwitch()
  .on(
    onCase("key1").then(chain1, chain2, chain3),
    onCase(key2").then(chain4, chain5),
  )

randomSwitch()
  .on(
    withWeight(double1).then(chain1, chain2, chain3),
    withWeight(double2).then(chain4, chain5),
  )
```

The existing Choice static factories are deprecated and will be removed in the next release.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant