-
Notifications
You must be signed in to change notification settings - Fork 7
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
Conversation
|
||
/*: Including Optionals */ | ||
|
||
let integerOptional = Int?.arbitrary.next(.random()) |
There was a problem hiding this comment.
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
|
||
/*: | ||
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
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.