Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
a-plus-abs-b
namespace FunctionalCSharp
{
using System;
using Shouldly;
using Xunit;
public class Tests
{
[Fact]
public void Elementary_blocks()
{
Func<int, int, bool> gt = (a, b) => a > b;
Func<int, int, int> add = (a, b) => a + b;
Func<int, int, int> sub = (a, b) => a - b;
Func<bool, Func<int, int, int>, Func<int, int, int>, Func<int, int, int>> @if =
(condition, @then, @else) => condition ? @then : @else;
Func<int, int, int> a_plus_abs_b = (a, b) => @if(gt(b, 0), add, sub)(a, b);
a_plus_abs_b(5, -4).ShouldBe(9);
}
[Fact]
public void Non_functional_way()
{
Func<int, int, int> a_plus_abs_b = (a, b) => a + Math.Abs(b);
a_plus_abs_b(5, -4).ShouldBe(9);
}
}
}
@shishkin
Owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.