|
| 1 | +namespace Funcky.Analyzers.Test; |
| 2 | + |
| 3 | +public sealed partial class AlternativeMonadAnalyzerTest |
| 4 | +{ |
| 5 | + // language=csharp |
| 6 | + private const string OptionStubCode = |
| 7 | + """ |
| 8 | + namespace Funcky.Monads |
| 9 | + { |
| 10 | + public readonly struct Option<TItem> |
| 11 | + where TItem : notnull |
| 12 | + { |
| 13 | + public static Option<TItem> None => default; |
| 14 | +
|
| 15 | + public static implicit operator Option<TItem>(TItem item) => default; |
| 16 | +
|
| 17 | + public TResult Match<TResult>(TResult none, System.Func<TItem, TResult> some) => default!; |
| 18 | +
|
| 19 | + public TResult Match<TResult>(System.Func<TResult> none, System.Func<TItem, TResult> some) => default!; |
| 20 | +
|
| 21 | + public TItem GetOrElse(TItem fallback) => default!; |
| 22 | +
|
| 23 | + public TItem GetOrElse(System.Func<TItem> fallback) => default!; |
| 24 | +
|
| 25 | + public Option<TItem> OrElse(Option<TItem> fallback) => default!; |
| 26 | +
|
| 27 | + public Option<TItem> OrElse(System.Func<Option<TItem>> fallback) => default!; |
| 28 | +
|
| 29 | + public Option<TResult> SelectMany<TResult>(System.Func<TItem, Option<TResult>> selector) where TResult : notnull => default; |
| 30 | + } |
| 31 | +
|
| 32 | + public static class OptionExtensions |
| 33 | + { |
| 34 | + public static TItem? ToNullable<TItem>(this Option<TItem> option, RequireStruct<TItem>? ω = null) where TItem : struct => default; |
| 35 | +
|
| 36 | + public static TItem? ToNullable<TItem>(this Option<TItem> option, RequireClass<TItem>? ω = null) where TItem : class => default; |
| 37 | + } |
| 38 | +
|
| 39 | + public static class Option |
| 40 | + { |
| 41 | + public static Option<TItem> Some<TItem>(TItem value) where TItem : notnull => default; |
| 42 | +
|
| 43 | + public static Option<TItem> Return<TItem>(TItem value) where TItem : notnull => default; |
| 44 | + } |
| 45 | +
|
| 46 | + public readonly struct Either<TLeft, TRight> |
| 47 | + where TLeft : notnull |
| 48 | + where TRight : notnull |
| 49 | + { |
| 50 | + public static Either<TLeft, TRight> Left(TLeft left) => default; |
| 51 | +
|
| 52 | + public static Either<TLeft, TRight> Right(TRight right) => default; |
| 53 | +
|
| 54 | + public TRight GetOrElse(TRight fallback) => default!; |
| 55 | +
|
| 56 | + public TRight GetOrElse(System.Func<TLeft, TRight> fallback) => default!; |
| 57 | +
|
| 58 | + public Either<TLeft, TRight> OrElse(Either<TLeft, TRight> fallback) => default; |
| 59 | +
|
| 60 | + public Either<TLeft, TRight> OrElse(System.Func<TLeft, Either<TLeft, TRight>> fallback) => default; |
| 61 | +
|
| 62 | + public Either<TLeft, TResult> SelectMany<TResult>(System.Func<TRight, Either<TLeft, TResult>> selector) where TResult : notnull => default; |
| 63 | +
|
| 64 | + public TMatchResult Match<TMatchResult>(System.Func<TLeft, TMatchResult> left, System.Func<TRight, TMatchResult> right) => default!; |
| 65 | + } |
| 66 | +
|
| 67 | + public static class Either<TLeft> |
| 68 | + where TLeft : notnull |
| 69 | + { |
| 70 | + public static Either<TLeft, TRight> Return<TRight>(TRight right) |
| 71 | + where TRight : notnull |
| 72 | + => default; |
| 73 | + } |
| 74 | +
|
| 75 | + public readonly struct Result<TValidResult> |
| 76 | + where TValidResult : notnull |
| 77 | + { |
| 78 | + public static Result<TValidResult> Error(System.Exception exception) => default; |
| 79 | +
|
| 80 | + public Result<TValidResult> OrElse(Result<TValidResult> fallback) => default; |
| 81 | +
|
| 82 | + public Result<TValidResult> OrElse(System.Func<System.Exception, Result<TValidResult>> fallback) => default; |
| 83 | +
|
| 84 | + public TValidResult GetOrElse(TValidResult fallback) => default!; |
| 85 | +
|
| 86 | + public TValidResult GetOrElse(System.Func<System.Exception, TValidResult> fallback) => default!; |
| 87 | +
|
| 88 | + public Result<TResult> SelectMany<TResult>(System.Func<TValidResult, Result<TResult>> selector) where TResult : notnull => default; |
| 89 | +
|
| 90 | + public TMatchResult Match<TMatchResult>(System.Func<TValidResult, TMatchResult> ok, System.Func<System.Exception, TMatchResult> error) => default!; |
| 91 | + } |
| 92 | +
|
| 93 | + public static class Result |
| 94 | + { |
| 95 | + public static Result<TValidResult> Ok<TValidResult>(TValidResult result) where TValidResult : notnull => default; |
| 96 | +
|
| 97 | + public static Result<TValidResult> Return<TValidResult>(TValidResult result) where TValidResult : notnull => default; |
| 98 | + } |
| 99 | +
|
| 100 | + public sealed class RequireStruct<T> where T : struct { } |
| 101 | +
|
| 102 | + public sealed class RequireClass<T> where T : class { } |
| 103 | + } |
| 104 | +
|
| 105 | + namespace Funcky |
| 106 | + { |
| 107 | + public static class Functional |
| 108 | + { |
| 109 | + public static T Identity<T>(T x) => x; |
| 110 | + } |
| 111 | + } |
| 112 | + """; |
| 113 | +} |
0 commit comments