Skip to content

Instantly share code, notes, and snippets.

@lanwin
Created March 3, 2011 15:06
Show Gist options
  • Save lanwin/852890 to your computer and use it in GitHub Desktop.
Save lanwin/852890 to your computer and use it in GitHub Desktop.
Simply object extension with provides an maybe monad.
public static class ObjectExtensions
{
public static IEnumerable<T> ToMaybe<T>(this T obj)
{
return Equals(obj,null) ? Enumerable.Empty<T>() : new[] {obj};
}
}
@ilkerde
Copy link

ilkerde commented Mar 4, 2011

A slight, but noteworthy difference. I don't know RX, so bare with me. I assumed that RX's Run() is the same as you have used it in your comment - which for me is a simple application like a commonly used ForEach-Extension does.

I wasn't aware of that "do" adds side effects without application. This fact actually is a clear indicator that i yet have a long learning path before me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment