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

tooling/templatize: use typed options, functional core #725

Merged
merged 1 commit into from
Oct 16, 2024

Conversation

stevekuznetsov
Copy link
Contributor

tooling/templatize: use typed options, functional core

The typed options pattern hides the validated and completed options in
opaque types that make it impossible for a consumer of the
ExecuteTemplate() function to pass some set of options that has NOT
been validated and completed. This makes it easy to trust the input and
make assumptions about it.

Furthermore, the Complete() implementation shows how to implement the
"imerative shell, functional core" pattern - imperative functionality
with side-effects like reading the filesystem can be done in a (small)
shell of imperative core, so that the real functionality of the library
is done in functional logic that is trivial to test.

An example of how to use this to our advantage is the new test for
template executioin - we pass raw data in, get raw data out. No need to
worry about filesytems, permissions, etc. We still can worry about
that in end-to-end tests if we need to.

Signed-off-by: Steve Kuznetsov stekuznetsov@microsoft.com


*: use bingo, add formatter target

Signed-off-by: Steve Kuznetsov stekuznetsov@microsoft.com


The typed options pattern hides the validated and completed options in
opaque types that make it impossible for a consumer of the
`ExecuteTemplate()` function to pass some set of options that has NOT
been validated and completed. This makes it easy to trust the input and
make assumptions about it.

Furthermore, the `Complete()` implementation shows how to implement the
"imerative shell, functional core" pattern - imperative functionality
with side-effects like reading the filesystem can be done in a (small)
shell of imperative core, so that the real functionality of the library
is done in functional logic that is trivial to test.

An example of how to use this to our advantage is the new test for
template executioin - we pass raw data in, get raw data out. No need to
worry about filesytems, permissions, etc. We still *can* worry about
that in end-to-end tests if we need to.

Signed-off-by: Steve Kuznetsov <stekuznetsov@microsoft.com>
@stevekuznetsov stevekuznetsov force-pushed the skuznets/templatize-testing branch from 224f707 to a472c1f Compare October 16, 2024 16:04
@geoberle geoberle merged commit 674df70 into main Oct 16, 2024
7 checks passed
@geoberle geoberle deleted the skuznets/templatize-testing branch October 16, 2024 16:39
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.

4 participants