paramarray

In F#, how do you curry ParamArray functions (like sprintf)?

瘦欲@ 提交于 2019-12-04 06:54:31
In F#, how do you curry a function that accepts a variable number of parameters? I have code like this...(the log function is just an example, the exact implementation doesn't matter) let log (msg : string) = printfn "%s" msg log "Sample" It gets called throughout the code with sprintf formatted strings, ex. log (sprintf "Test %s took %d seconds" "foo" 2.345) I want to curry the sprintf functionality in the log function so it looks like... logger "Test %s took %d seconds" "foo" 2.345 I've tried something like let logger fmt ([<ParamArray>] args) = log (sprintf fmt args) but I cannot figure out

Using a ParamArray, but requiring at least one parameter

对着背影说爱祢 提交于 2019-12-03 15:31:38
What I used to have: Public Sub Subscribe(channel As ChannelType) Public Sub Subscribe(channels As IEnumerable(Of ChannelType)) The first one just calls the second one with {channel} to convert its parameter into an array. I decided that having to create a list of channels to pass to the method was awkward and chose to combine the two overloads into one method that takes a ParamArray . Public Sub Subscribe(ParamArray channels() As ChannelType) 'Usage Subscribe(ChannelType.News) Subscribe(ChannelType.News, ChannelType.Sports) Subscribe() 'Oops... this is valid What is the "best practice" here?

Delegates and ParamArray - Workaround Suggestions?

大城市里の小女人 提交于 2019-12-01 17:53:58
Some predefined methods contain a ParamArray in their signature. Delegates, however, cannot contain a ParamArray in their signature. Question: Assume you wish to create a delegation mechanism for a specific method which requires a ParamArray. How would you work around this constraint? EDIT: just to make clear, assume you cannot change the method signatures themselves (pre-defined methods, defined by some 3rd party, be it Microsoft or not). EDIT2: The real deal here is keeping the syntax sugar , because the following code does work, but eliminates the sugar: Public Delegate Sub MyDelegate(ByVal

Pass array to ParamArray

倾然丶 夕夏残阳落幕 提交于 2019-11-30 08:27:03
is it possible to pass all elements of an array to a ParamArray? For example I'd like to pass a ParamArray to another ParamArray: Sub test() p1 "test", "banane", "birne" End Sub Sub p1(ParamArray keys() As Variant) p2 keys 'should be the same as: p2 "test", "banane", "birne" End Sub Sub p2(ParamArray keys() As Variant) Dim key As Variant For Each key In keys Debug.Print key 'Run-time error '13' Type mismatch (key is an array) Next key End Sub In this case ParamArray of p2 doesn't contain the elements of keys , but it gets the array-object keys . Thus I've got to check, if an arrays is passed: