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

Composing generators playground #48

Merged
merged 8 commits into from
May 13, 2022

Conversation

rafaeloliveira13
Copy link
Contributor

composing-ex.mov

Develop Composing with Operators Playground.
There are a lot of operators already done and some being developed, so I added a base with some important ones.
Created with rendered markup.


/*: Including Optionals */

let integerOptional = Int?.arbitrary.next(.random())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way to write this could be Int.arbitrary.orNil().next(.random()) if you think that it's better, since it shows off another operator

orNil()


/*:
The approach shown above has two problems: the syntax is not very ergonomic - there are 2 .next calls and we need to send the same random source to both if we want to maintain predictability.
We can solve it using the flatmap operator inside Genything.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can solve it using the flatmap operator inside Genything.

We can solve both aforementioned problems using flatMap.

🤔

generatorOfRandomGenerators.next(.random()).next(.predetermined())

/*:
The approach shown above has two problems: the syntax is not very ergonomic - there are 2 .next calls and we need to send the same random source to both if we want to maintain predictability.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can use markdown lists here?
Something like:

The approach shown above has two problems:

1. The syntax is not very ergonomic.
2. Two `next` calls are required to produce a value, and we will need to send the same random source to both calls if we want to maintain predictability.

]

/*:
Let's choose a random generator by turning it into a generator.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could mention meta-generators or inception here 🤣

examples / text
@rafaeloliveira13 rafaeloliveira13 merged commit 87e4073 into main May 13, 2022
@rafaeloliveira13 rafaeloliveira13 deleted the composing-generators-playground branch May 13, 2022 20:01
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

Successfully merging this pull request may close these issues.

3 participants