예제 #1
0
        public static void Run()
        {
            // 1 Write a generic function that takes a string and parses it as a value of an enum. It
            // should be usable as follows:

            Option <DayOfWeek> a = Enum.Parse <DayOfWeek>("Friday"); // => Some(DayOfWeek.Friday)

            // Enum.Parse<DayOfWeek>("Freeday") // => None

            // 2 Write a Lookup function that will take an IEnumerable and a predicate, and
            // return the first element in the IEnumerable that matches the predicate, or None
            // if no matching element is found. Write its signature in arrow notation:

            bool isOdd(int i) => i % 2 == 1;

            var b = new List <int>().Lookup(isOdd); // => None
            var c = new List <int> {
                1
            }.Lookup(isOdd);                           // => Some(1)

            // 3 email thing
            // Email is a type using a smart constructor to return a new Email(string) if the string is valid
            Option <Email> email = Email.Create("*****@*****.**");

            var x = Thing.Create();
        }
예제 #2
0
 public static Option <DayOfWeek> GetDay(string input)
 {
     return(Enum.Parse <DayOfWeek>(input));
 }