Skip to content

Commit bc7ea78

Browse files
committed
feat: add NotEqualsFunction for inequality comparison across multiple types
1 parent 47248af commit bc7ea78

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
namespace Compo.Functions.Logical;
2+
3+
/// <summary>
4+
/// Inequality comparison.
5+
/// Returns true if values are not equal.
6+
/// Convenience function equivalent to not(equals(a, b)).
7+
/// </summary>
8+
[FunctionRegistration("neq")]
9+
public class NotEqualsFunction :
10+
IFunction<string, string, bool>,
11+
IFunction<int, int, bool>,
12+
IFunction<double, double, bool>,
13+
IFunction<decimal, decimal, bool>,
14+
IFunction<bool, bool, bool>
15+
{
16+
public bool Execute(string a, string b)
17+
{
18+
return !string.Equals(a, b, StringComparison.Ordinal);
19+
}
20+
21+
public bool Execute(int a, int b)
22+
{
23+
return a != b;
24+
}
25+
26+
public bool Execute(double a, double b)
27+
{
28+
return System.Math.Abs(a - b) >= double.Epsilon;
29+
}
30+
31+
public bool Execute(decimal a, decimal b)
32+
{
33+
return a != b;
34+
}
35+
36+
public bool Execute(bool a, bool b)
37+
{
38+
return a != b;
39+
}
40+
}

0 commit comments

Comments
 (0)