-
Notifications
You must be signed in to change notification settings - Fork 3
/
CurryParams.cs
45 lines (37 loc) · 1.54 KB
/
CurryParams.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
using System;
using System.Dynamic;
using static Ramda.NET.Currying;
namespace Ramda.NET
{
internal class CurryParams : AbstractLambda
{
internal CurryParams(DynamicDelegate fn) : base(fn, 2) {
}
internal CurryParams(Delegate fn) : this(new DelegateDecorator(fn)) {
}
protected override object TryInvoke(InvokeBinder binder, object[] arguments) {
var arg1IsPlaceHolder = false;
var arg2IsPlaceHolder = false;
var length = arguments.Length;
if (length == 0) {
return new Curry2(fn);
}
else {
var arg1 = arguments[0];
switch (arguments.Length) {
case 1:
return IsPlaceholder(arg1) ? (AbstractLambda)new Curry2(fn) : new Curry1(new Func<object, object>(_arg2 => fn(arg1, _arg2)));
default:
var arg2 = arguments[1];
arg1IsPlaceHolder = IsPlaceholder(arg1);
arg2IsPlaceHolder = IsPlaceholder(arg2);
return arg1IsPlaceHolder && arg2IsPlaceHolder ? (AbstractLambda)new Curry2(fn) : arg1IsPlaceHolder ? new Curry1(new Func<object, object>(_arg1 => {
return fn(_arg1, arg2);
})) : arg2IsPlaceHolder ? new Curry1(new Func<object, object>(_arg2 => {
return fn(arg1, _arg2);
})) : fn(arg1, arg2);
}
}
}
}
}