Permalink
Browse files

Maybe<T>: Fixed bug in Cast and OfType...

  • Loading branch information...
1 parent 442d64e commit 257937ece049516c3207f74421c04fcd6baa1466 @iSynaptic committed Jun 14, 2011
@@ -2,7 +2,7 @@
<package>
<metadata>
<id>iSynaptic.Commons.Data</id>
- <version>0.1.0.40</version>
+ <version>0.1.0.41</version>
<authors>Jordan Terrell</authors>
<description>Standard Implementation of Exodata Resolver - Ioc for Data</description>
<language>en-US</language>
@@ -13,7 +13,7 @@
<frameworkAssembly assemblyName="System.Core" targetFramework="net40" />
</frameworkAssemblies>
<dependencies>
- <dependency id="iSynaptic.Commons" version="0.1.0.40" />
+ <dependency id="iSynaptic.Commons" version="0.1.0.41" />
</dependencies>
</metadata>
<files>
@@ -671,13 +671,13 @@ public static Maybe<TResult> Cast<TResult>(this IMaybe self)
return Value(self)
.Select(x =>
{
- if (self.Exception != null)
- return new Maybe<TResult>(self.Exception);
+ if (x.Exception != null)
+ return new Maybe<TResult>(x.Exception);
- if (self.HasValue != true)
+ if (x.HasValue != true)
return Maybe<TResult>.NoValue;
- return (TResult) self.Value;
+ return (TResult) x.Value;
});
}
@@ -686,8 +686,19 @@ public static Maybe<TResult> OfType<TResult>(this IMaybe self)
Guard.NotNull(self, "self");
return Value(self)
- .Where(x => x.HasValue && x.Value is TResult)
- .Cast<TResult>();
+ .Select(x =>
+ {
+ if (x.Exception != null)
+ return new Maybe<TResult>(x.Exception);
+
+ if (x.HasValue != true)
+ return Maybe<TResult>.NoValue;
+
+ if(x.Value is TResult)
+ return (TResult)x.Value;
+
+ return Maybe<TResult>.NoValue;
+ });
}
public static T? ToNullable<T>(this Maybe<T> self) where T : struct
@@ -2,7 +2,7 @@
<package>
<metadata>
<id>iSynaptic.Commons</id>
- <version>0.1.0.40</version>
+ <version>0.1.0.41</version>
<authors>Jordan Terrell</authors>
<description>Library of common functionality in functional programming style.</description>
<language>en-US</language>
View
@@ -14,5 +14,5 @@
[assembly: ComVisible(false)]
[assembly: CLSCompliant(true)]
-[assembly: AssemblyVersion("0.1.0.40")]
-[assembly: AssemblyFileVersion("0.1.0.40")]
+[assembly: AssemblyVersion("0.1.0.41")]
+[assembly: AssemblyFileVersion("0.1.0.41")]

0 comments on commit 257937e

Please sign in to comment.