-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add F# snippets for System.Action #7352
Conversation
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. |
Docs Build status updates of commit aa91752: ✅ Validation status: passed
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:
|
@KathleenDollard - can you review? |
cc @baronfel as well, in case you are interested in reviewing. |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 :)
Docs Build status updates of commit 687206a: ✅ Validation status: passed
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:
|
@BillWagner this is ready! |
I apologize for the delay @albert-du This dropped off my radar. Merging now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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