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

TransformerGenerator: support external functor types #12

Merged
merged 3 commits into from
Jun 17, 2024

Conversation

jeffijoe
Copy link
Contributor

@jeffijoe jeffijoe commented Jun 16, 2024

This PR adds support for generating transformer methods for functors that are external to the consumer. This means that consumers can now use [Functor] and [GenerateTransformer] on their own types and have methods generated that have the FxKit types on the outside.

Example:

using FxKit.CompilerServices;

namespace App;

[Functor]
public record Box<T>(T Item);

public static class Box
{
    [GenerateTransformer] // will have a transformer generated, and will be used by generated transformers.
    public static Box<U> Map<T, U>(this Box<T> source, Func<T, U> selector) =>
        new Box<U>(selector(source.Item));

    [GenerateTransformer] // will have a transformer generated
    public static T Unwrap(this Box<T> box) => box.Item;
}

This will now result in MapT and UnwrapT-variant being generated for every known functor type based on project references as well as assembly references.

var box = new Box<int>(2);
var outer = Task.FromResult(box);
Task<Box<string>> mapped = outer.MapT(x => x.ToString());
Task<string> unwrapped = mapped.UnwrapT();

Additionally, the generator has been restructured to properly take advantage of incremental generation. Before, the generator was run on virtually any change.

@jeffijoe jeffijoe requested review from radyz, Xepe and jcorkhill June 16, 2024 02:02
@jeffijoe jeffijoe force-pushed the feat/consume-transformer-generator branch 3 times, most recently from 8b01528 to 6ed2d28 Compare June 17, 2024 12:26
docs/compiler/transformer.md Outdated Show resolved Hide resolved
docs/compiler/transformer.md Outdated Show resolved Hide resolved
docs/compiler/transformer.md Outdated Show resolved Hide resolved
docs/core/index.md Outdated Show resolved Hide resolved
docs/core/index.md Show resolved Hide resolved
docs/introduction.md Outdated Show resolved Hide resolved
docs/introduction.md Outdated Show resolved Hide resolved
@jeffijoe jeffijoe force-pushed the feat/consume-transformer-generator branch from 6ed2d28 to 7b326aa Compare June 17, 2024 15:15
@jeffijoe jeffijoe requested a review from jcorkhill June 17, 2024 15:15
@jeffijoe jeffijoe merged commit cfbc55a into main Jun 17, 2024
2 checks passed
@jeffijoe jeffijoe deleted the feat/consume-transformer-generator branch June 17, 2024 15:21
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