Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This doesn't avoid the boilerplate requirement for every <code>Func</code> and every possible number of "late" arguments, but I just want to show the "simple" approach is still fairly clean. VB's just a bit verbose for it to seem like it is a useful construct.</p> <p>Also the current <code>Curry</code> definition doesn't implicitly work without the <code>Of</code> types being explicitly specified in the call :-(</p> <p>EDIT: Show the implicit option does work for explicit <code>Func</code> variables.</p> <pre class="lang-vb prettyprint-override"><code> Option Explicit On Option Strict On Option Infer On Imports System Imports Microsoft.VisualBasic Module CurryTest Function Test1(ByVal X As String, ByVal Y As String) As String Return X &amp; Y End Function Function Test2(ByVal X As Integer, ByVal Y As Integer) As Integer Return X + Y End Function Function Test3(ByVal X As Integer, ByVal Y As Integer, ByVal Z As String) As String Return Z &amp; ":" &amp; CStr(X + Y) End Function Sub Main() Dim Curry1 = Curry(Of String, String, String)(AddressOf Test1, "a") Dim Curry2 = Curry(Of Integer, Integer, Integer)(AddressOf Test2, 2) Dim Curry3 = Curry(Of Integer, Integer, String, String)(AddressOf Test3, 1, 2) Dim f As Func(Of String, String, String) = AddressOf Test1 Dim g As Func(Of Integer, Integer, Integer) = AddressOf Test2 Dim h As Func(Of Integer, Integer, String, String) = AddressOf Test3 Dim Curry4 = Curry(f, "b") Dim Curry5 = Curry(g, 3) Dim Curry6 = Curry(h, 4, 5) Console.WriteLine(Curry1("b")) Console.WriteLine(Curry1("c")) Console.WriteLine(Curry2(2)) Console.WriteLine(Curry2(3)) Console.WriteLine(Curry3("Three")) Console.WriteLine(Curry3("3 ")) Console.WriteLine(Curry4("c")) Console.WriteLine(Curry4("d")) Console.WriteLine(Curry5(4)) Console.WriteLine(Curry5(5)) Console.WriteLine(Curry6("Nine")) Console.WriteLine(Curry6("9 ")) End Sub Function Curry(Of T, U, V)(ByVal Fn As Func(Of T, U, V), ByVal Arg As T) As Func(Of U, V) Return Function(Arg2 As U)(Fn(Arg,Arg2)) End Function Function Curry(Of T, U, V, W)(ByVal Fn As Func(Of T, U, V, W), ByVal Arg1 As T, ByVal Arg2 As U) As Func(Of V, W) Return Function(Arg3 As V)(Fn(Arg1,Arg2,Arg3)) End Function End Module </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload