Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6a73326

Browse files
dsymeKevinRansom
authored andcommitted
[FS-1045] Add FuncConvert.FromFunc, FuncConvert.FromAction APIs (dotnet#4815)
* add func overloads* adjust based on C# testing* fix test break* fix test* update surface area* fix test* align inlines* Merge error
1 parentfce9e68 commit6a73326

File tree

9 files changed

+215
-44
lines changed

9 files changed

+215
-44
lines changed

‎src/fsharp/FSharp.Core/Linq.fs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -782,11 +782,7 @@ module LeafExpressionConverter =
782782
typedefof<Action<_>>, tyargs
783783
else
784784
lettyargs=[| vP.Type; bodyP.Type|]
785-
#if FX_NO_CONVERTER
786785
typedefof<Func<_,_>>, tyargs
787-
#else
788-
typedefof<System.Converter<_,_>>, tyargs
789-
#endif
790786
letconvType= lambdaTy.MakeGenericType tyargs
791787
letconvDelegate= Expression.Lambda(convType, bodyP,[| vP|])|> asExpr
792788
Expression.Call(typeof<FuncConvert>,"ToFSharpFunc", tyargs,[| convDelegate|])|> asExpr

‎src/fsharp/FSharp.Core/prim-types.fs‎

Lines changed: 63 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2884,40 +2884,82 @@ namespace Microsoft.FSharp.Core
28842884

28852885

28862886
typeFSharpFunc<'T,'Res>with
2887-
#if FX_NO_CONVERTER
2887+
2888+
// Note: this is not made public in the signature, because of conflicts with the Converter overload.
2889+
// The method remains in case someone is calling it via reflection.
28882890
[<CodeAnalysis.SuppressMessage("Microsoft.Usage","CA2225:OperatorOverloadsHaveNamedAlternates")>]
2889-
static memberop_Implicit(func:System.Func<_,_>):('T-> 'Res) =(fun t-> func.Invoke(t))
2891+
static memberop_Implicit(converter:System.Func<_,_>):('T-> 'Res) =(fun t-> converter.Invoke(t))
2892+
2893+
// Note: this is not made public in the signature, because of conflicts with the Converter overload.
2894+
// The method remains in case someone is calling it via reflection.
28902895
[<CodeAnalysis.SuppressMessage("Microsoft.Usage","CA2225:OperatorOverloadsHaveNamedAlternates")>]
2891-
static memberop_Implicit(func:('T-> 'Res) )=new System.Func<'T,'Res>(func)
2892-
#else
2896+
static memberop_Implicit(func:('T-> 'Res) )=new System.Func<'T,'Res>(func)
2897+
2898+
#if!FX_NO_CONVERTER
28932899
[<CodeAnalysis.SuppressMessage("Microsoft.Usage","CA2225:OperatorOverloadsHaveNamedAlternates")>]
2894-
static memberop_Implicit(converter:System.Converter<_,_>):('T-> 'Res) =(fun t-> converter.Invoke(t))
2900+
static memberop_Implicit(f:System.Converter<_,_>):('T-> 'Res) =(fun t-> f.Invoke(t))
2901+
28952902
[<CodeAnalysis.SuppressMessage("Microsoft.Usage","CA2225:OperatorOverloadsHaveNamedAlternates")>]
28962903
static memberop_Implicit(func:('T-> 'Res) )=new System.Converter<'T,'Res>(func)
28972904

2898-
static memberFromConverter(converter:System.Converter<_,_>):('T-> 'Res) =(fun t-> converter.Invoke(t))
2899-
static memberToConverter(func:('T-> 'Res) )=new System.Converter<'T,'Res>(func)
2905+
static memberFromConverter(converter:System.Converter<_,_>):('T-> 'Res) =(fun t-> converter.Invoke(t))
2906+
2907+
static memberToConverter(func:('T-> 'Res) )=new System.Converter<'T,'Res>(func)
29002908
#endif
2901-
static memberInvokeFast(func:FSharpFunc<_,_>,arg1:'T,arg2:'Res)= OptimizedClosures.invokeFast2(func, arg1, arg2)
2902-
static memberInvokeFast(func:FSharpFunc<_,_>,arg1:'T,arg2:'Res,arg3)= OptimizedClosures.invokeFast3(func, arg1, arg2, arg3)
2903-
static memberInvokeFast(func:FSharpFunc<_,_>,arg1:'T,arg2:'Res,arg3,arg4)= OptimizedClosures.invokeFast4(func, arg1, arg2, arg3, arg4)
2904-
static memberInvokeFast(func:FSharpFunc<_,_>,arg1:'T,arg2:'Res,arg3,arg4,arg5)= OptimizedClosures.invokeFast5(func, arg1, arg2, arg3, arg4, arg5)
2909+
2910+
static memberInvokeFast(func:FSharpFunc<_,_>,arg1:'T,arg2:'Res)= OptimizedClosures.invokeFast2(func, arg1, arg2)
2911+
2912+
static memberInvokeFast(func:FSharpFunc<_,_>,arg1:'T,arg2:'Res,arg3)= OptimizedClosures.invokeFast3(func, arg1, arg2, arg3)
2913+
2914+
static memberInvokeFast(func:FSharpFunc<_,_>,arg1:'T,arg2:'Res,arg3,arg4)= OptimizedClosures.invokeFast4(func, arg1, arg2, arg3, arg4)
2915+
2916+
static memberInvokeFast(func:FSharpFunc<_,_>,arg1:'T,arg2:'Res,arg3,arg4,arg5)= OptimizedClosures.invokeFast5(func, arg1, arg2, arg3, arg4, arg5)
29052917

29062918
[<AbstractClass>]
29072919
[<Sealed>]
29082920
typeFuncConvert=
2909-
static memberToFSharpFunc(action:Action<_>)=(fun t-> action.Invoke(t))
2910-
#if FX_NO_CONVERTER
2911-
static memberToFSharpFunc(converter:System.Func<_,_>)=(fun t-> converter.Invoke(t))
2912-
#else
2913-
static memberToFSharpFunc(converter:Converter<_,_>)=(fun t-> converter.Invoke(t))
2914-
#endif
2915-
static memberFuncFromTupled(func:'T1* 'T2-> 'Res)=(fun a b-> func(a, b))
2916-
static memberFuncFromTupled(func:'T1* 'T2* 'T3-> 'Res)=(fun a b c-> func(a, b, c))
2917-
static memberFuncFromTupled(func:'T1* 'T2* 'T3* 'T4-> 'Res)=(fun a b c d-> func(a, b, c, d))
2918-
static memberFuncFromTupled(func:'T1* 'T2* 'T3* 'T4* 'T5-> 'Res)=(fun a b c d e-> func(a, b, c, d, e))
29192921

2922+
static memberinline ToFSharpFunc(action:Action<_>)=(fun t-> action.Invoke(t))
2923+
2924+
#if!FX_NO_CONVERTER
2925+
static memberinline ToFSharpFunc(converter:Converter<_,_>)=(fun t-> converter.Invoke(t))
2926+
#endif
2927+
2928+
// Note: this is not made public in the signature, because of conflicts with the Converter overload.
2929+
// The method remains in case someone is calling it via reflection.
2930+
static memberinline ToFSharpFunc(converter:System.Func<_,_>)=(fun t-> converter.Invoke(t))
2931+
2932+
static memberinline FromFunc(func:System.Func<_>)=(fun()-> func.Invoke())
2933+
2934+
static memberinline FromFunc(func:System.Func<_,_>)=(fun t-> func.Invoke(t))
29202935

2936+
static memberinline FromFunc(func:System.Func<_,_,_>)=(fun t1 t2-> func.Invoke(t1,t2))
2937+
2938+
static memberinline FromFunc(func:System.Func<_,_,_,_>)=(fun t1 t2 t3-> func.Invoke(t1,t2,t3))
2939+
2940+
static memberinline FromFunc(func:System.Func<_,_,_,_,_>)=(fun t1 t2 t3 t4-> func.Invoke(t1,t2,t3,t4))
2941+
2942+
static memberinline FromFunc(func:System.Func<_,_,_,_,_,_>)=(fun t1 t2 t3 t4 t5-> func.Invoke(t1,t2,t3,t4,t5))
2943+
2944+
static memberinline FromAction(action:System.Action)=(fun()-> action.Invoke())
2945+
2946+
static memberinline FromAction(action:System.Action<_>)=(fun t-> action.Invoke(t))
2947+
2948+
static memberinline FromAction(action:System.Action<_,_>)=(fun t1 t2-> action.Invoke(t1,t2))
2949+
2950+
static memberinline FromAction(action:System.Action<_,_,_>)=(fun t1 t2 t3-> action.Invoke(t1,t2,t3))
2951+
2952+
static memberinline FromAction(action:System.Action<_,_,_,_>)=(fun t1 t2 t3 t4-> action.Invoke(t1,t2,t3,t4))
2953+
2954+
static memberinline FromAction(action:System.Action<_,_,_,_,_>)=(fun t1 t2 t3 t4 t5-> action.Invoke(t1,t2,t3,t4,t5))
2955+
2956+
static member inlineFuncFromTupled(func:'T1* 'T2-> 'Res)=(fun a b-> func(a, b))
2957+
2958+
static member inlineFuncFromTupled(func:'T1* 'T2* 'T3-> 'Res)=(fun a b c-> func(a, b, c))
2959+
2960+
static member inlineFuncFromTupled(func:'T1* 'T2* 'T3* 'T4-> 'Res)=(fun a b c d-> func(a, b, c, d))
2961+
2962+
static member inlineFuncFromTupled(func:'T1* 'T2* 'T3* 'T4* 'T5-> 'Res)=(fun a b c d e-> func(a, b, c, d, e))
29212963

29222964
//-------------------------------------------------------------------------
29232965
// Refs
@@ -5433,7 +5475,6 @@ namespace Microsoft.FSharp.Core
54335475
letTanhDynamic x= TanhDynamicImplTable<_>.Result x
54345476
letPowDynamic x y= PowDynamicImplTable<_,_>.Result x y
54355477

5436-
54375478
openOperatorIntrinsics
54385479

54395480
let inline(..)(start:^T)(finish:^T)=

‎src/fsharp/FSharp.Core/prim-types.fsi‎

Lines changed: 76 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,16 +1445,17 @@ namespace Microsoft.FSharp.Core
14451445
[<AbstractClass>]
14461446
type FSharpFunc<'T,'U>=
14471447

1448-
///<summary>Construct an instance of an F#first class function value </summary>
1449-
///<returns>The created F#function.</returns>
1448+
///<summary>Construct an instance of an F#first class function value </summary>
1449+
///<returns>The created F#function.</returns>
14501450
new:unit->FSharpFunc<'T,'U>
1451-
1451+
14521452
///<summary>Invoke an F#first class function value with one argument</summary>
14531453
///<param name="func"></param>
14541454
///<returns>'U</returns>
14551455
abstract member Invoke:func:'T-> 'U
14561456

14571457
#if!FX_NO_CONVERTER
1458+
14581459
///<summary>Convert an F#first class function value to a value of type <c>System.Converter</c></summary>
14591460
///<param name="func">The input function.</param>
14601461
///<returns>A System.Converter of the function type.</returns>
@@ -1469,6 +1470,7 @@ namespace Microsoft.FSharp.Core
14691470
///<param name="func">The input function.</param>
14701471
///<returns>System.Converter&lt;'T,'U&gt;</returns>
14711472
static member ToConverter:func:('T-> 'U)->System.Converter<'T,'U>
1473+
14721474
///<summary>Convert an value of type <c>System.Converter</c> to a F#first class function value </summary>
14731475
///<param name="converter">The input System.Converter.</param>
14741476
///<returns>An F#function of the same type.</returns>
@@ -1520,36 +1522,96 @@ namespace Microsoft.FSharp.Core
15201522
type FuncConvert=
15211523

15221524
///<summary>Convert the given Action delegate object to an F#function value</summary>
1523-
///<param name="action">The inputaction.</param>
1525+
///<param name="action">The inputAction delegate.</param>
15241526
///<returns>The F#function.</returns>
1525-
static member ToFSharpFunc:action:Action<'T>->('T->unit)
1527+
static memberinlineToFSharpFunc:action:Action<'T>->('T->unit)
15261528

15271529
#if!FX_NO_CONVERTER
15281530
///<summary>Convert the given Converter delegate object to an F#function value</summary>
1529-
///<param name="converter">The input Converter.</param>
1531+
///<param name="converter">The input Converter delegate.</param>
15301532
///<returns>The F#function.</returns>
1531-
static member ToFSharpFunc:converter:Converter<'T,'U>->('T-> 'U)
1533+
static memberinlineToFSharpFunc:converter:Converter<'T,'U>->('T-> 'U)
15321534
#endif
15331535

1536+
///<summary>Convert the given Action delegate object to an F#function value</summary>
1537+
///<param name="func">The input Action delegate.</param>
1538+
///<returns>The F#function.</returns>
1539+
static member inline FromAction:action:Action->(unit->unit)
1540+
1541+
///<summary>Convert the given Action delegate object to an F#function value</summary>
1542+
///<param name="func">The input Action delegate.</param>
1543+
///<returns>The F#function.</returns>
1544+
static member inline FromAction:action:Action<'T>->('T->unit)
1545+
1546+
///<summary>Convert the given Action delegate object to an F#function value</summary>
1547+
///<param name="func">The input Action delegate.</param>
1548+
///<returns>The F#funcfunction.</returns>
1549+
static member inline FromAction:action:Action<'T1,'T2>->('T1-> 'T2->unit)
1550+
1551+
///<summary>Convert the given Action delegate object to an F#function value</summary>
1552+
///<param name="func">The input Action delegate.</param>
1553+
///<returns>The F#function.</returns>
1554+
static member inline FromAction:action:Action<'T1,'T2,'T3>->('T1-> 'T2-> 'T3->unit)
1555+
1556+
///<summary>Convert the given Action delegate object to an F#function value</summary>
1557+
///<param name="func">The input Action delegate.</param>
1558+
///<returns>The F#function.</returns>
1559+
static member inline FromAction:action:Action<'T1,'T2,'T3,'T4>->('T1-> 'T2-> 'T3-> 'T4->unit)
1560+
1561+
///<summary>Convert the given Action delegate object to an F#function value</summary>
1562+
///<param name="func">The input Action delegate.</param>
1563+
///<returns>The F#function.</returns>
1564+
static member inline FromAction:action:Action<'T1,'T2,'T3,'T4,'T5>->('T1-> 'T2-> 'T3-> 'T4-> 'T5->unit)
1565+
1566+
///<summary>Convert the given Func delegate object to an F#function value</summary>
1567+
///<param name="func">The input Func delegate.</param>
1568+
///<returns>The F#function.</returns>
1569+
static member inline FromFunc:func:Func<'T>->(unit-> 'T)
1570+
1571+
///<summary>Convert the given Func delegate object to an F#function value</summary>
1572+
///<param name="func">The input Func delegate.</param>
1573+
///<returns>The F#function.</returns>
1574+
static member inline FromFunc:func:Func<'T,'U>->('T-> 'U)
1575+
1576+
///<summary>Convert the given Func delegate object to an F#function value</summary>
1577+
///<param name="func">The input Func delegate.</param>
1578+
///<returns>The F#funcfunction.</returns>
1579+
static member inline FromFunc:func:Func<'T1,'T2,'U>->('T1-> 'T2-> 'U)
1580+
1581+
///<summary>Convert the given Func delegate object to an F#function value</summary>
1582+
///<param name="func">The input Func delegate.</param>
1583+
///<returns>The F#function.</returns>
1584+
static member inline FromFunc:func:Func<'T1,'T2,'T3,'U>->('T1-> 'T2-> 'T3-> 'U)
1585+
1586+
///<summary>Convert the given Func delegate object to an F#function value</summary>
1587+
///<param name="func">The input Func delegate.</param>
1588+
///<returns>The F#function.</returns>
1589+
static member inline FromFunc:func:Func<'T1,'T2,'T3,'T4,'U>->('T1-> 'T2-> 'T3-> 'T4-> 'U)
1590+
1591+
///<summary>Convert the given Func delegate object to an F#function value</summary>
1592+
///<param name="func">The input Func delegate.</param>
1593+
///<returns>The F#function.</returns>
1594+
static member inline FromFunc:func:Func<'T1,'T2,'T3,'T4,'T5,'U>->('T1-> 'T2-> 'T3-> 'T4-> 'T5-> 'U)
1595+
15341596
///<summary>A utility function to convert function values from tupled to curried form</summary>
15351597
///<param name="func">The input tupled function.</param>
15361598
///<returns>The output curried function.</returns>
1537-
static member FuncFromTupled:func:('T1* 'T2-> 'U)->('T1-> 'T2-> 'U)
1599+
static memberinlineFuncFromTupled:func:('T1* 'T2-> 'U)->('T1-> 'T2-> 'U)
15381600

15391601
///<summary>A utility function to convert function values from tupled to curried form</summary>
15401602
///<param name="func">The input tupled function.</param>
15411603
///<returns>The output curried function.</returns>
1542-
static member FuncFromTupled:func:('T1* 'T2* 'T3-> 'U)->('T1-> 'T2-> 'T3-> 'U)
1604+
static memberinlineFuncFromTupled:func:('T1* 'T2* 'T3-> 'U)->('T1-> 'T2-> 'T3-> 'U)
15431605

15441606
///<summary>A utility function to convert function values from tupled to curried form</summary>
15451607
///<param name="func">The input tupled function.</param>
15461608
///<returns>The output curried function.</returns>
1547-
static member FuncFromTupled:func:('T1* 'T2* 'T3* 'T4-> 'U)->('T1-> 'T2-> 'T3-> 'T4-> 'U)
1609+
static memberinlineFuncFromTupled:func:('T1* 'T2* 'T3* 'T4-> 'U)->('T1-> 'T2-> 'T3-> 'T4-> 'U)
15481610

15491611
///<summary>A utility function to convert function values from tupled to curried form</summary>
15501612
///<param name="func">The input tupled function.</param>
15511613
///<returns>The output curried function.</returns>
1552-
static member FuncFromTupled:func:('T1* 'T2* 'T3* 'T4* 'T5-> 'U)->('T1-> 'T2-> 'T3-> 'T4-> 'T5-> 'U)
1614+
static memberinlineFuncFromTupled:func:('T1* 'T2* 'T3* 'T4* 'T5-> 'U)->('T1-> 'T2-> 'T3-> 'T4-> 'T5-> 'U)
15531615

15541616
///<summary>An implementation module used to hold some private implementations of function
15551617
///value invocation.</summary>
@@ -1584,6 +1646,7 @@ namespace Microsoft.FSharp.Core
15841646
///typically used directly from either F#code or from other CLI languages.</summary>
15851647
[<AbstractClass>]
15861648
type FSharpFunc<'T1,'T2,'T3,'U>=
1649+
15871650
inherit FSharpFunc<'T1,('T2-> 'T3-> 'U)>
15881651

15891652
///<summary>Invoke an F#first class function value that accepts three curried arguments
@@ -1626,6 +1689,7 @@ namespace Microsoft.FSharp.Core
16261689
///<param name="func">The input function.</param>
16271690
///<returns>The optimized function.</returns>
16281691
static member Adapt:func:('T1-> 'T2-> 'T3-> 'T4-> 'U)->FSharpFunc<'T1,'T2,'T3,'T4,'U>
1692+
16291693
///<summary>Construct an optimized function value that can accept four curried
16301694
///arguments without intervening execution.</summary>
16311695
///<returns>The optimized function.</returns>
@@ -3204,6 +3268,7 @@ namespace Microsoft.FSharp.Control
32043268
module LazyExtensions=
32053269

32063270
type System.Lazy<'T> with
3271+
32073272
///<summary>Creates a lazy computation that evaluates to the result of the given function when forced.</summary>
32083273
///<param name="creator">The function to provide the value when needed.</param>
32093274
///<returns>The created Lazy object.</returns>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp