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

🪚 OmniGraph™ Delusional code of the utterly deranged #112

Merged
merged 8 commits into from
Dec 13, 2023

Conversation

janjakubnanista
Copy link
Contributor

@janjakubnanista janjakubnanista commented Dec 13, 2023

In this PR

This is a precursor for even more extensible tooling because the sky is the limit. It is a restricted and mutated version of a basic Monoid and a Semigroup for Promises.

The problem

Once a promise is created, there is no way of doing something before it starts. There is also no way of saying oh I want these promises to happen in a certain order which is limiting, in the most tangible case, when asking for user input on the CLI.

On the CLI, you can only ask for one thing at a time. If the user needs to answer a question e.g. for every single contract, they need to be asked these questions one by one.

At this moment the code relies on strategies such as Promise.all which require you to pass in an array of promises (remember, you can't stop a promise). If in any of these promises we need to ask user for some input, this input will be printed out in parallel which is incomprehensible to the CLI and results in broken software (all the questions will be answered at once and will be answered with the first input that the user types in)

The solution

The solution is a wrapper around a Promise, commonly referred to as a Task. Task is a function that generates a promise when required - but it will not start the promise until asked to do so.

Tasks are much more flexible than Promises since we can prevent them from happening, postpone or arrange them.

For now, the only tooling we require for Tasks are so-called Monoids and Semigroups. These are very simple mathematical structures consisting of a type S and an operation that transforms S + S → S (and in case of a Monoid we also get an empty element).

In our case we get rid of the purity a bit and simplify some of the steps when it comes to the mathematics in order to get a better UX. We get a parallel and sequence "monoids" - not truly monoids because instead of operating on two elements they operate on N elements and instead of returning a Task they execute the task for us; and a first "semigroups" - again, a bit simplified for the purpose of UX.

These structures allow us to control the behavior of functions to our liking - for example in a non-interactive case we might be okay with executing graph transformations in parallel, in an interactive case we might go with sequential execution.

Example

For example, our Options together with OptionsBuilder are a monoid - you can merge two options using the builder and the empty state is 0x

image

@janjakubnanista janjakubnanista changed the title 🪚 OmniGraph™ 🪚 OmniGraph™ Delusional code of the utterly deranged Dec 13, 2023
Copy link

@0xIryna 0xIryna left a comment

Choose a reason for hiding this comment

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

🙌 👏 🍉

@Thomas-S-Kim
Copy link

LayerMonad?

@janjakubnanista janjakubnanista merged commit dcf1bbb into main Dec 13, 2023
1 check passed
@janjakubnanista janjakubnanista deleted the ominchain-config--21--deployment branch December 13, 2023 23:32
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