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

Refactoring: Extract Interface from Type member declaration (refactoring) #1227

Open
4 tasks done
jkone27 opened this issue Feb 2, 2024 · 0 comments
Open
4 tasks done

Comments

@jkone27
Copy link
Contributor

jkone27 commented Feb 2, 2024

Details

would be great to be able to easilly extract an abstact type (interface) from a type with a public member, and have it implement (interface with) that interface,

with just 1 context action.

Reason

  • interfaces in F# look quite odd, due to type signatures differing from actual implementation signatures, this confuses quite many people getting started with F# i believe
// LIGHT BULB HERE ---> extract all public members to interface, also useful..
type TripFaqMapper( ... ) =

        // LIGHT BULB HERE! --> here suggestion lights up, as this is a public member, possibly can be extracted to interface
        member this.MapGroupTagAsync
            (
                id: int64,
                groupCode: string,
                tag: string,
                appId: string,
                locale,
                currency,
                cancellationToken: CancellationToken
            ) : TravixFaqResponse Task =

            task {...} // implementation



// generates this, like in C# extract interface..

type TripFaqMapper( ... ) =

    interface ITripFaqMapper with

        member this.MapGroupTagAsync
            (
                id: int64,
                groupCode: string,
                tag: string,
                appId: string,
                locale,
                currency,
                cancellationToken: CancellationToken
            ) : TravixFaqResponse Task =

            task {...} // implementation


type ITripFaqMapper =
    abstract member MapGroupTagAsync:
        id: int64 *
        groupCode: string *
        tag: string *
        appId: string *
        locale: Locale *
        currency: Currency *
        cancellationToken: CancellationToken ->
            TravixFaqResponse Task
  • interfaces are only part of OO world, but having a great time C# interoperability should be always important and useful

  • helps .NET developers be less scared of F# to also know they can easilly make regular class types with interfaces and inject them in their DI containers of habit, like what is provided in HostBuilder and Aspnetcore by default.

Checklist

  • I have looked through existing issues to make sure that this feature has not been requested before
  • I have provided a descriptive title for this issue
  • I am aware that even valid feature requests may be rejected if they do not align with the project's goals
  • I or my company would be willing to contribute this feature
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant