Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Created by SharpDevelop.
- * User: zeonni
- * Date: 29.09.2016
- * Time: 16:07
- *
- * To change this template use Tools | Options | Coding | Edit Standard Headers.
- */
- using System;
- namespace Maybe
- {
- class Program
- {
- public static void Main(string[] args)
- {
- welcome(new Maybe<String>("Onni"));
- welcome(new Maybe<String>(null));
- Console.ReadKey();
- }
- public static void welcome(Maybe<String> user) {
- Console.WriteLine(
- user.Take<String>(
- (name) => String.Format("Welcome, {0}!", name),
- () => "User not auth"
- )
- );
- }
- }
- class Maybe<T> {
- public delegate R Just<R>(T value);
- public delegate R Nothing<R>();
- private T value;
- public Maybe(T value) {
- this.value = value;
- }
- public R Take<R>(Just<R> just, Nothing<R> nothing) {
- return value == null ? nothing() : just(value);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement