diff --git a/.gitignore b/.gitignore index 58f27dc..eab16d5 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ TestResults/* *.suo *.user _ReSharper.* +*.nupkg diff --git a/May.sln b/May.sln index 21ab815..92c41bb 100644 --- a/May.sln +++ b/May.sln @@ -1,34 +1,22 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.23107.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "May", "May\May.csproj", "{37468DFC-8378-4F4F-94F2-39F5C1AB8C5A}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MayTest", "MayTest\MayTest.csproj", "{B27038A2-7CFF-41B0-8FB6-DD38BBBD740C}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MayExample", "MayExample\MayExample.csproj", "{D7365D22-E675-4319-8A9C-779497B852AD}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {37468DFC-8378-4F4F-94F2-39F5C1AB8C5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {37468DFC-8378-4F4F-94F2-39F5C1AB8C5A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {37468DFC-8378-4F4F-94F2-39F5C1AB8C5A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {37468DFC-8378-4F4F-94F2-39F5C1AB8C5A}.Release|Any CPU.Build.0 = Release|Any CPU - {B27038A2-7CFF-41B0-8FB6-DD38BBBD740C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B27038A2-7CFF-41B0-8FB6-DD38BBBD740C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B27038A2-7CFF-41B0-8FB6-DD38BBBD740C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B27038A2-7CFF-41B0-8FB6-DD38BBBD740C}.Release|Any CPU.Build.0 = Release|Any CPU - {D7365D22-E675-4319-8A9C-779497B852AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D7365D22-E675-4319-8A9C-779497B852AD}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D7365D22-E675-4319-8A9C-779497B852AD}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D7365D22-E675-4319-8A9C-779497B852AD}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "May", "May\May.csproj", "{37468DFC-8378-4F4F-94F2-39F5C1AB8C5A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {37468DFC-8378-4F4F-94F2-39F5C1AB8C5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {37468DFC-8378-4F4F-94F2-39F5C1AB8C5A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {37468DFC-8378-4F4F-94F2-39F5C1AB8C5A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {37468DFC-8378-4F4F-94F2-39F5C1AB8C5A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/May/IMayHaveValue.cs b/May/IMayHaveValue.cs index 122866f..b79aac1 100644 --- a/May/IMayHaveValue.cs +++ b/May/IMayHaveValue.cs @@ -14,7 +14,6 @@ namespace Strilanc.Value { [EditorBrowsable(EditorBrowsableState.Never)] public interface IMayHaveValue : IEquatable { ///Determines if this potential value contains a value or not. - [Pure] bool HasValue { get; } } } diff --git a/May/May-dotnet.nuspec b/May/May-dotnet.nuspec new file mode 100644 index 0000000..50a57a4 --- /dev/null +++ b/May/May-dotnet.nuspec @@ -0,0 +1,20 @@ + + + + May-dotnet + 1.1.0 + curve25519 for .NETStandard + Craig Gidney + Strilanc + https://github.com/Strilanc/May/blob/master/License.txt + https://github.com/Strilanc/May + false + Description is required. + dotnet standard, here we come! + Copyright 2017 + May netstandard + + + + + diff --git a/May/May.cs b/May/May.cs index 6904707..c494101 100644 --- a/May/May.cs +++ b/May/May.cs @@ -15,24 +15,20 @@ public struct May : IMayHaveValue, IEquatable> { ///Note: All forms of no value are equal, including May.NoValue, May<T>.NoValue, May<AnyOtherT>.NoValue, default(May<T>) and new May<T>(). ///Note: Null is NOT equivalent to new May<object>(null) and neither is equivalent to new May<string>(null). /// - [Pure] public static May NoValue { get { return default(May); } } private readonly T _value; private readonly bool _hasValue; ///Determines if this potential value contains a value or not. - [Pure] public bool HasValue { get { return _hasValue; } } ///Constructs a potential value containing the given value. - [Pure] public May(T value) { this._hasValue = true; this._value = value; } ///Matches this potential value into either a function expecting a value or a function expecting no value, returning the result. - [Pure] public TOut Match(Func valueProjection, Func alternativeFunc) { if (valueProjection == null) throw new ArgumentNullException("valueProjection"); if (alternativeFunc == null) throw new ArgumentNullException("alternativeFunc"); diff --git a/May/May.csproj b/May/May.csproj index 4c778e4..7810261 100644 --- a/May/May.csproj +++ b/May/May.csproj @@ -1,105 +1,107 @@ - - - - - 10.0 - Debug - AnyCPU - {37468DFC-8378-4F4F-94F2-39F5C1AB8C5A} - Library - Properties - Strilanc.Value - May - v4.0 - Profile136 - 512 - {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - - - - - 4.0 - 0 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - bin\Debug\May.XML - False - False - True - False - False - False - True - True - True - True - True - True - True - True - False - True - False - True - False - False - False - False - True - False - True - True - True - False - False - - - - - - - - True - False - False - True - Full - Build - 0 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - bin\Release\May.XML - - - - - - - - - - - - - + + + + + 14.0 + Debug + AnyCPU + {37468DFC-8378-4F4F-94F2-39F5C1AB8C5A} + Library + Properties + Strilanc.Value + May + v5.0 + + + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + + + + + 4.0 + 0 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + bin\Debug\May.XML + False + False + True + False + False + False + True + True + True + True + True + True + True + True + False + True + False + True + False + False + False + False + True + False + True + True + True + False + False + + + + + + + + True + False + False + True + Full + Build + 0 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + bin\Release\May.XML + + + + + + + + + + + + + + + --> \ No newline at end of file diff --git a/May/MayExtensions.cs b/May/MayExtensions.cs index 0440139..54b7c52 100644 --- a/May/MayExtensions.cs +++ b/May/MayExtensions.cs @@ -9,67 +9,55 @@ public static class May { ///Note: All forms of no value are equal, including May.NoValue, May<T>.NoValue, May<AnyOtherT>.NoValue, default(May<T>) and new May<T>(). ///Note: Null is NOT equivalent to new May<object>(null) and neither is equivalent to new May<string>(null). /// - [Pure] public static MayNoValue NoValue { get { return default(MayNoValue); } } ///Returns a potential value containing the given value. - [Pure] public static May Maybe(this T value) { return new May(value); } ///Matches this potential value either into a function expecting a value or against an alternative value. - [Pure] public static TOut Match(this May potentialValue, Func valueProjection, TOut alternative) { if (valueProjection == null) throw new ArgumentNullException("valueProjection"); return potentialValue.Match(valueProjection, () => alternative); } ///Returns the potential result of potentially applying the given function to this potential value. - [Pure] public static May Bind(this May potentialValue, Func> projection) { if (projection == null) throw new ArgumentNullException("projection"); return potentialValue.Match(projection, () => NoValue); } ///Returns the value contained in the given potential value, if any, or else the result of evaluating the given alternative value function. - [Pure] public static T Else(this May potentialValue, Func alternativeFunc) { if (alternativeFunc == null) throw new ArgumentNullException("alternativeFunc"); return potentialValue.Match(e => e, alternativeFunc); } ///Flattens a doubly-potential value, with the result containing a value only if both levels contained a value. - [Pure] public static May Unwrap(this May> potentialValue) { return potentialValue.Bind(e => e); } ///Returns the value contained in the given potential value, if any, or else the result of evaluating the given alternative potential value function. - [Pure] public static May Else(this May potentialValue, Func> alternative) { if (alternative == null) throw new ArgumentNullException("alternative"); return potentialValue.Match(e => e.Maybe(), alternative); } ///Returns the value contained in the given potential value, if any, or else the given alternative value. - [Pure] public static T Else(this May potentialValue, T alternative) { return potentialValue.Else(() => alternative); } ///Returns the value contained in the given potential value, if any, or else the given alternative potential value. - [Pure] public static May Else(this May potentialValue, May alternative) { return potentialValue.Else(() => alternative); } ///Returns the result of potentially applying a function to this potential value. - [Pure] public static May Select(this May value, Func projection) { if (projection == null) throw new ArgumentNullException("projection"); return value.Bind(e => projection(e).Maybe()); } ///Returns the same value, unless the contained value does not match the filter in which case a no value is returned. - [Pure] public static May Where(this May value, Func filter) { if (filter == null) throw new ArgumentNullException("filter"); return value.Bind(e => filter(e) ? e.Maybe() : NoValue); } ///Projects optional values, returning a no value if anything along the way is a no value. - [Pure] public static May SelectMany(this May source, Func> maySelector, Func resultSelector) { @@ -78,7 +66,6 @@ public static May SelectMany(this May source, return source.Bind(s => maySelector(s).Select(m => resultSelector(s, m))); } ///Combines the values contained in several potential values with a projection function, returning no value if any of the inputs contain no value. - [Pure] public static May Combine(this May potentialValue1, May potentialValue2, Func resultSelector) { @@ -88,7 +75,6 @@ from v2 in potentialValue2 select resultSelector(v1, v2); } ///Combines the values contained in several potential values with a projection function, returning no value if any of the inputs contain no value. - [Pure] public static May Combine(this May potentialValue1, May potentialValue2, May potentialValue3, @@ -100,7 +86,6 @@ from v3 in potentialValue3 select resultSelector(v1, v2, v3); } ///Combines the values contained in several potential values with a projection function, returning no value if any of the inputs contain no value. - [Pure] public static May Combine(this May potentialValue1, May potentialValue2, May potentialValue3, @@ -118,7 +103,6 @@ from v4 in potentialValue4 /// No effect if the potential value is no value. /// Returns an IMayHaveValue that has a value iff the action was run. /// - [Pure] public static IMayHaveValue IfHasValueThenDo(this May potentialValue, Action hasValueAction) { if (hasValueAction == null) throw new ArgumentNullException("hasValueAction"); return potentialValue.Select(e => { @@ -127,20 +111,17 @@ public static IMayHaveValue IfHasValueThenDo(this May potentialValue, Acti }); } ///Runs the given no value action if the given potential value does not contain a value, and otherwise does nothing. - [Pure] public static void ElseDo(this IMayHaveValue potentialValue, Action noValueAction) { if (potentialValue == null) throw new ArgumentNullException("potentialValue"); if (noValueAction == null) throw new ArgumentNullException("noValueAction"); if (!potentialValue.HasValue) noValueAction(); } ///Returns the value contained in the given potential value, if any, or else the type's default value. - [Pure] public static T ElseDefault(this May potentialValue) { return potentialValue.Else(default(T)); } ///Returns the value contained in the potential value, or throws an InvalidOperationException if it contains no value. - [Pure] public static T ForceGetValue(this May potentialValue) { return potentialValue.Match( e => e, diff --git a/May/MayNoValue.cs b/May/MayNoValue.cs index 8fe6449..ccdeb1c 100644 --- a/May/MayNoValue.cs +++ b/May/MayNoValue.cs @@ -13,7 +13,6 @@ namespace Strilanc.Value { [DebuggerDisplay("{ToString()}")] public struct MayNoValue : IMayHaveValue { ///Determines if this potential value contains a value or not (it doesn't). - [Pure] public bool HasValue { get { return false; } } ///Returns the hash code for a lack of potential value. public override int GetHashCode() { diff --git a/May/MayUtilities.cs b/May/MayUtilities.cs index cd24f26..1842bcf 100644 --- a/May/MayUtilities.cs +++ b/May/MayUtilities.cs @@ -7,13 +7,11 @@ namespace Strilanc.Value { ///Utility methods that involve May<T> but with a focus on other types. public static class MayUtilities { ///Returns the value contained in the given potential value as a nullable type, returning null if there is no contained value. - [Pure] public static T? AsNullable(this May potentialValue) where T : struct { return potentialValue.Select(e => (T?)e).ElseDefault(); } ///Returns the value contained in the given nullable value as a potential value, with null corresponding to no value. - [Pure] public static May AsMay(this T? potentialValue) where T : struct { if (!potentialValue.HasValue) return May.NoValue; return potentialValue.Value; @@ -23,7 +21,6 @@ public static May AsMay(this T? potentialValue) where T : struct { /// Returns the result of using a folder function to combine all the items in the sequence into one aggregate item. /// If the sequence is empty, the result is NoValue. /// - [Pure] public static May MayAggregate(this IEnumerable sequence, Func folder) { if (sequence == null) throw new ArgumentNullException("sequence"); if (folder == null) throw new ArgumentNullException("folder"); @@ -36,7 +33,6 @@ public static May MayAggregate(this IEnumerable sequence, Func /// Returns the minimum value in a sequence, as determined by the given comparer or else the type's default comparer. /// If the sequence is empty, the result is NoValue. /// - [Pure] public static May MayMin(this IEnumerable sequence, IComparer comparer = null) { if (sequence == null) throw new ArgumentNullException("sequence"); var c = comparer ?? Comparer.Default; @@ -47,7 +43,6 @@ public static May MayMin(this IEnumerable sequence, IComparer compar /// Returns the maximum value in a sequence, as determined by the given comparer or else the type's default comparer. /// If the sequence is empty, the result is NoValue. /// - [Pure] public static May MayMax(this IEnumerable sequence, IComparer comparer = null) { if (sequence == null) throw new ArgumentNullException("sequence"); var c = comparer ?? Comparer.Default; @@ -58,7 +53,6 @@ public static May MayMax(this IEnumerable sequence, IComparer compar /// Returns the minimum value in a sequence, as determined by projecting the items and using the given comparer or else the type's default comparer. /// If the sequence is empty, the result is NoValue. /// - [Pure] public static May MayMinBy(this IEnumerable sequence, Func projection, IComparer comparer = null) { if (sequence == null) throw new ArgumentNullException("sequence"); var c = comparer ?? Comparer.Default; @@ -72,7 +66,6 @@ public static May MayMinBy(this IEnumerable seque /// Returns the maximum value in a sequence, as determined by projecting the items and using the given comparer or else the type's default comparer. /// If the sequence is empty, the result is NoValue. /// - [Pure] public static May MayMaxBy(this IEnumerable sequence, Func projection, IComparer comparer = null) { if (sequence == null) throw new ArgumentNullException("sequence"); var c = comparer ?? Comparer.Default; @@ -83,7 +76,6 @@ public static May MayMaxBy(this IEnumerable seque } ///Returns the first item in a sequence, or else NoValue if the sequence is empty. - [Pure] public static May MayFirst(this IEnumerable sequence) { if (sequence == null) throw new ArgumentNullException("sequence"); using (var e = sequence.GetEnumerator()) @@ -93,7 +85,6 @@ public static May MayFirst(this IEnumerable sequence) { } ///Returns the last item in a sequence, or else NoValue if the sequence is empty. - [Pure] public static May MayLast(this IEnumerable sequence) { if (sequence == null) throw new ArgumentNullException("sequence"); @@ -108,7 +99,6 @@ public static May MayLast(this IEnumerable sequence) { } ///Returns the single item in a sequence, NoValue if the sequence is empty, or throws an exception if there is more than one item. - [Pure] public static May MaySingle(this IEnumerable sequence) { if (sequence == null) throw new ArgumentNullException("sequence"); @@ -125,7 +115,6 @@ public static May MaySingle(this IEnumerable sequence) { /// Enumerates the values in the potential values in the sequence. /// The potential values that contain no value are skipped. /// - [Pure] public static IEnumerable WhereHasValue(this IEnumerable> sequence) { return sequence.Where(e => e.HasValue).Select(e => (T)e); } @@ -134,7 +123,6 @@ public static IEnumerable WhereHasValue(this IEnumerable> sequence) /// Enumerates the values in all the potential values in the sequence. /// However, if any of the potential values contains no value then the entire result is no value. /// - [Pure] public static May> MayAll(this IEnumerable> sequence) { if (sequence == null) throw new ArgumentNullException("sequence"); var result = new List(); diff --git a/May/project.json b/May/project.json new file mode 100644 index 0000000..2632940 --- /dev/null +++ b/May/project.json @@ -0,0 +1,10 @@ +{ + "supports": {}, + "dependencies": { + "Microsoft.NETCore.Portable.Compatibility": "1.0.1", + "NETStandard.Library": "1.6.0" + }, + "frameworks": { + "netstandard1.5": {} + } +} \ No newline at end of file