-
Notifications
You must be signed in to change notification settings - Fork 3
/
Curry3.cs
69 lines (62 loc) · 2.85 KB
/
Curry3.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Dynamic;
using static Ramda.NET.Currying;
using System.Collections.Generic;
namespace Ramda.NET
{
internal class Curry3 : AbstractLambda
{
internal Curry3(DynamicDelegate fn) : base(fn, 3) {
}
internal Curry3(Delegate fn) : base(new DelegateDecorator(fn)) {
}
protected override object TryInvoke(InvokeBinder binder, object[] arguments) {
object arg1 = null;
object arg2 = null;
object arg3 = null;
var arg1IsPlaceHolder = false;
var arg2IsPlaceHolder = false;
var arg3IsPlaceHolder = false;
var arity = Currying.Arity(arguments);
if (arity > 0) {
arg1 = arguments[0];
}
switch (arity) {
case 0:
return Curry3(fn);
case 1:
return IsPlaceholder(arg1) ? Curry3(fn) : Curry2((_arg2, _arg3) => fn(arg1, _arg2, _arg3));
case 2:
arg2 = arguments[1];
arg1IsPlaceHolder = IsPlaceholder(arg1);
arg2IsPlaceHolder = IsPlaceholder(arg2);
return (arg1IsPlaceHolder = IsPlaceholder(arg1)) && (arg2IsPlaceHolder = IsPlaceholder(arg2)) ? Curry3(fn) : arg1IsPlaceHolder ? Curry2((_arg1, _arg3) => {
return fn(_arg1, arg2, _arg3);
}) : arg2IsPlaceHolder ? Curry2((_arg2, _arg3) => {
return fn(arg1, _arg2, _arg3);
}) : Curry1(_arg3 => {
return fn(arg1, arg2, _arg3);
});
default:
arg2 = arguments[1];
arg3 = arguments[2];
arg1IsPlaceHolder = IsPlaceholder(arg1);
arg2IsPlaceHolder = IsPlaceholder(arg2);
arg3IsPlaceHolder = IsPlaceholder(arg3);
return arg1IsPlaceHolder && arg2IsPlaceHolder && arg3IsPlaceHolder ? Curry3(fn) : arg1IsPlaceHolder && arg2IsPlaceHolder ? Curry2((_arg1, _arg2) => {
return fn(_arg1, _arg2, arg3);
}) : arg1IsPlaceHolder && arg3IsPlaceHolder ? Curry2((_arg1, _arg3) => {
return fn(_arg1, arg2, _arg3);
}) : arg2IsPlaceHolder && arg3IsPlaceHolder ? Curry2((_arg2, _arg3) => {
return fn(arg1, _arg2, _arg3);
}) : arg1IsPlaceHolder ? Curry1(_arg1 => {
return fn(_arg1, arg2, arg3);
}) : arg2IsPlaceHolder ? Curry1(_arg2 => {
return fn(arg1, _arg2, arg3);
}) : arg3IsPlaceHolder ? Curry1(_arg3 => {
return fn(arg1, arg2, _arg3);
}) : fn(arg1, arg2, arg3);
}
}
}
}