├── assets
└── icon.png
├── src
├── SharpX
│ ├── Types
│ │ ├── Result
│ │ │ ├── ResultType.cs
│ │ │ ├── Bad.cs
│ │ │ ├── Ok.cs
│ │ │ ├── ResultOfT.cs
│ │ │ ├── ResultExtensions.cs
│ │ │ └── Trial.cs
│ │ ├── Either
│ │ │ ├── EitherType.cs
│ │ │ ├── EitherOfT.cs
│ │ │ ├── Either.cs
│ │ │ └── EitherExtensions.cs
│ │ ├── Maybe
│ │ │ ├── MaybeType.cs
│ │ │ ├── MaybeOfT.cs
│ │ │ ├── Maybe.cs
│ │ │ └── MaybeExtensions.cs
│ │ └── Unit.cs
│ ├── paket.references
│ ├── Extensions
│ │ ├── ExceptionExtensions.cs
│ │ ├── UnitExtensions.cs
│ │ ├── ObjectExtensions.cs
│ │ ├── LoggerExtensions.cs
│ │ ├── FSharpResultExtensions.cs
│ │ └── StringExtensions.cs
│ ├── FsCheck
│ │ ├── ArbitraryString.cs
│ │ ├── ArbitraryIntegerSeq.cs
│ │ ├── ArbitraryStringSeq.cs
│ │ └── ArbitraryValue.cs
│ ├── SharpX.csproj
│ ├── Utilities
│ │ ├── Guard.cs
│ │ └── CryptoRandom.cs
│ └── Primitives.cs
└── .editorconfig
├── .gitignore
├── .editorconfig
├── tests
├── SharpX.Tests
│ ├── paket.references
│ ├── SharpX.Tests.csproj
│ ├── Outcomes
│ │ ├── ResultSpecs.cs
│ │ ├── ObjectExtensionsSpecs.cs
│ │ ├── TrailSpecs.cs
│ │ ├── UnitSpecs.cs
│ │ ├── EitherSpecs.cs
│ │ ├── LoggerExtensionsSpecs.cs
│ │ ├── FSharpResultExtensionsSpecs.cs
│ │ ├── PrimitivesSpecs.cs
│ │ ├── StringExtensionsSpecs.cs
│ │ ├── StringsSpecs.cs
│ │ ├── MaybeSpecs.cs
│ │ └── EnumerableExtensionsSpecs.cs
│ └── Tests
│ │ ├── SimpleValidation.cs
│ │ └── NightClubsValidation.cs
└── .editorconfig
├── paket.dependencies
├── Directory.Build.props
├── LICENSE
├── SharpX.sln
├── paket.lock
├── README.md
└── CHANGELOG.md
/assets/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gsscoder/sharpx/HEAD/assets/icon.png
--------------------------------------------------------------------------------
/src/SharpX/Types/Result/ResultType.cs:
--------------------------------------------------------------------------------
1 | namespace SharpX;
2 |
3 | public enum ResultType
4 | {
5 | Bad,
6 | Ok
7 | }
8 |
--------------------------------------------------------------------------------
/src/SharpX/paket.references:
--------------------------------------------------------------------------------
1 | group main
2 | FSharp.Core
3 | FsCheck
4 | Microsoft.NETCore.Platforms
5 | Microsoft.Extensions.Logging.Abstractions
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .vscode/
3 | .vs
4 | tools/
5 | [Oo]bj/
6 | [Bb]in/
7 | .nuget/
8 | _ReSharper.*
9 | packages/
10 | artifacts/
11 | *.user
12 | *.suo
13 | *.userprefs
14 | *DS_Store
15 | *.sln.ide
16 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | []
4 | end_of_line = crlf
5 | insert_final_newline = true
6 |
7 | [*.xml]
8 | indent_style = space
9 | indent_size = 4
10 |
11 | [*.{json,yml}]
12 | indent_style = space
13 | indent_size = 2
14 |
--------------------------------------------------------------------------------
/src/SharpX/Extensions/ExceptionExtensions.cs:
--------------------------------------------------------------------------------
1 | namespace SharpX.Extensions;
2 |
3 | public static class ExceptionExtensions
4 | {
5 | public static string Format(this Exception exception) => Primitives.FormatException(exception);
6 | }
7 |
--------------------------------------------------------------------------------
/src/SharpX/Extensions/UnitExtensions.cs:
--------------------------------------------------------------------------------
1 | namespace SharpX.Extensions;
2 |
3 | public static class UnitExtensions
4 | {
5 | /// Joins more Unit instances.
6 | public static Unit And(this Unit _, Unit second) => second;
7 | }
8 |
--------------------------------------------------------------------------------
/tests/SharpX.Tests/paket.references:
--------------------------------------------------------------------------------
1 | group tests
2 | FluentAssertions
3 | FsCheck
4 | FsCheck.Xunit
5 | Microsoft.NET.Test.Sdk
6 | xunit
7 | xunit.runner.visualstudio
8 | coverlet.collector
9 | Microsoft.NETCore.Platforms
10 | Moq
11 |
--------------------------------------------------------------------------------
/src/SharpX/Types/Either/EitherType.cs:
--------------------------------------------------------------------------------
1 | namespace SharpX;
2 |
3 | /// Discriminator for Either.
4 | public enum EitherType
5 | {
6 | /// Failed computation case.
7 | Left,
8 | /// Sccessful computation case.
9 | Right
10 | }
11 |
--------------------------------------------------------------------------------
/src/SharpX/Types/Maybe/MaybeType.cs:
--------------------------------------------------------------------------------
1 | namespace SharpX;
2 |
3 | /// Discriminator for Maybe.
4 | public enum MaybeType
5 | {
6 | /// Computation case without a value.
7 | Nothing,
8 | /// Computation case with a value.
9 | Just
10 | }
11 |
--------------------------------------------------------------------------------
/src/SharpX/FsCheck/ArbitraryString.cs:
--------------------------------------------------------------------------------
1 | using FsCheck;
2 | using FsCheck.Fluent;
3 |
4 | namespace SharpX.FsCheck;
5 |
6 | public static class ArbitraryString
7 | {
8 | public static Arbitrary Generator() => Gen.OneOf(Gen.Constant(null),
9 | Gen.Constant(Strings.Generate(9))).ToArbitrary();
10 | }
11 |
--------------------------------------------------------------------------------
/src/SharpX/FsCheck/ArbitraryIntegerSeq.cs:
--------------------------------------------------------------------------------
1 | using FsCheck;
2 | using FsCheck.Fluent;
3 |
4 | namespace SharpX.FsCheck;
5 |
6 | public static class ArbitraryIntegerSeq
7 | {
8 | public static Arbitrary Generator()
9 | {
10 | var seq = Primitives.GenerateSeq(count: 100);
11 |
12 | return Gen.Shuffle(seq).ToArbitrary();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/SharpX/Extensions/ObjectExtensions.cs:
--------------------------------------------------------------------------------
1 | namespace SharpX.Extensions;
2 |
3 | public static class ObjectExtensions
4 | {
5 | /// Discards a value and return Unit.
6 | public static Unit ToUnit(this T value) => Unit.Default;
7 |
8 | /// Returns true in case of a numeric type value, otherwise false.
9 | public static bool IsNumber(this T? value) => Primitives.IsNumber(value);
10 | }
11 |
--------------------------------------------------------------------------------
/src/SharpX/Types/Result/Bad.cs:
--------------------------------------------------------------------------------
1 | namespace SharpX;
2 |
3 | /// Represents the result of a failed computation.
4 | public sealed class Bad : Result
5 | {
6 | private readonly IEnumerable _messages;
7 |
8 | public Bad(IEnumerable messages)
9 | : base(ResultType.Bad)
10 | {
11 | Guard.DisallowNull(nameof(messages), messages);
12 |
13 | _messages = messages;
14 | }
15 |
16 | public IEnumerable Messages => _messages;
17 | }
18 |
--------------------------------------------------------------------------------
/src/SharpX/FsCheck/ArbitraryStringSeq.cs:
--------------------------------------------------------------------------------
1 | using FsCheck;
2 | using FsCheck.Fluent;
3 | using SharpX.Extensions;
4 |
5 | namespace SharpX.FsCheck;
6 |
7 | public static class ArbitraryStringSeq
8 | {
9 | public static Arbitrary Generator()
10 | {
11 | var seq = Primitives.GenerateSeq(() => Strings.Generate(9), count: 20)
12 | .Concat(Enumerable.Range(0, 9).Select(x => x.ToString()))
13 | .Intersperse(null)
14 | .Intersperse(string.Empty);
15 |
16 | return Gen.Shuffle(seq).ToArbitrary();
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/tests/SharpX.Tests/SharpX.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | net8.0
8 | 13.0
9 | false
10 | gsscoder
11 | gsscoder
12 | SharpX
13 | CS0618
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/SharpX/Types/Result/Ok.cs:
--------------------------------------------------------------------------------
1 | namespace SharpX;
2 |
3 | /// Represents the result of a successful computation.
4 | public sealed class Ok : Result
5 | {
6 | private readonly TSuccess _success;
7 | private readonly IEnumerable _messages;
8 |
9 | public Ok(TSuccess success, IEnumerable messages)
10 | : base(ResultType.Ok)
11 | {
12 | Guard.DisallowNull(nameof(success), success);
13 | Guard.DisallowNull(nameof(messages), messages);
14 |
15 | _success = success;
16 | _messages = messages;
17 | }
18 |
19 | public TSuccess Success => _success;
20 |
21 | public IEnumerable Messages => _messages;
22 | }
23 |
--------------------------------------------------------------------------------
/tests/SharpX.Tests/Outcomes/ResultSpecs.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable 0618
2 |
3 | using System;
4 | using System.Linq;
5 | using FluentAssertions;
6 | using SharpX;
7 | using Xunit;
8 |
9 | namespace Outcomes;
10 |
11 | public class Result
12 | {
13 | [Fact]
14 | public void Should_fail_when_Try_catches_an_exception()
15 | {
16 | var exn = new Exception("Hello World");
17 | var result = Result