Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add F# snippets for System.Action #7352

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

Merged
merged 3 commits into from
Nov 22, 2021

Conversation

albert-du
Copy link
Contributor

Summary

Adds F# code snippets for System.Action

The behaviors are identical to the other languages

I didn't translate the anonymous method snippet as they aren't a thing in F# as far as I know

The article itself might benefit from a remark about F# first class functions as an alternative to delegates but I didn't include anything of the sort here

@ghost
Copy link

ghost commented Nov 4, 2021

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@opbld32
Copy link

opbld32 commented Nov 4, 2021

Docs Build status updates of commit aa91752:

✅ Validation status: passed

File Status Preview URL Details
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Action/fs/Action.fs ✅Succeeded View
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Action/fs/Action.fsproj ✅Succeeded
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Action/fs/Delegate.fs ✅Succeeded View
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Action/fs/Lambda.fs ✅Succeeded View
xml/System/Action.xml ✅Succeeded View

For more details, please refer to the build report.

Note: Broken links written as relative paths are included in the above build report. For broken links written as absolute paths or external URLs, see the broken link report.

For any questions, please:

@albert-du albert-du marked this pull request as ready for review November 4, 2021 05:55
@albert-du albert-du requested a review from a team as a code owner November 4, 2021 05:55
@eerhardt
Copy link
Member

eerhardt commented Nov 4, 2021

@KathleenDollard - can you review?

@albert-du
Copy link
Contributor Author

@dsyme

@eerhardt
Copy link
Member

cc @baronfel as well, in case you are interested in reviewing.

Copy link
Member

@baronfel baronfel left a comment

Choose a reason for hiding this comment

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

These all look perfectly good, just a style comment.

Separately, the doc page for Action calls out C# and VB in particular in a few places:

(In C#, the method must return void. In Visual Basic, it must be defined by the Sub…End Sub construct. It can also be a method that returns a value that is ignored.)

This could be expanded to mention the unit -> unit relationship you mention in your comment!

You can also use the Action delegate with anonymous methods in C#, as the following example illustrates. (For an introduction to anonymous methods, see Anonymous Methods.)

It might be nice to have a parallel to lambas in F# and a link here?

open System.Windows.Forms

type Name(name) =
let instanceName = name
Copy link
Member

Choose a reason for hiding this comment

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

In F# we don't need the explicit local field set; in DisplayToConsole and DisplayToWindow we are able to use the name directly. I'm guessing that this form what chosen to maintain symmetry with the C# samples? I'm not sure that's necessary to be honest.

type ShowValue = delegate of unit -> unit

type Name(name) =
let instanceName = name
Copy link
Member

Choose a reason for hiding this comment

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

Same comment here, I think we can be a bit more slim, plus it helps highlight and show off the scoping available to F# classes!

open System.Windows.Forms

type Name(name) =
let instanceName = name
Copy link
Member

Choose a reason for hiding this comment

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

Third time's the charm :)

@opbld31
Copy link

opbld31 commented Nov 13, 2021

Docs Build status updates of commit 687206a:

✅ Validation status: passed

File Status Preview URL Details
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Action/fs/Action.fs ✅Succeeded View
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Action/fs/Action.fsproj ✅Succeeded
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Action/fs/Delegate.fs ✅Succeeded View
samples/snippets/fsharp/VS_Snippets_CLR_System/system.Action/fs/Lambda.fs ✅Succeeded View
xml/System/Action.xml ✅Succeeded View

For more details, please refer to the build report.

Note: Broken links written as relative paths are included in the above build report. For broken links written as absolute paths or external URLs, see the broken link report.

For any questions, please:

@albert-du
Copy link
Contributor Author

@BillWagner this is ready!

@BillWagner
Copy link
Member

I apologize for the delay @albert-du This dropped off my radar.

Merging now.

Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

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

LGTM

@BillWagner BillWagner merged commit 7510963 into dotnet:main Nov 22, 2021
@albert-du albert-du deleted the system.action-fsharp-snippets branch January 19, 2022 20:44
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.

7 participants