-
Notifications
You must be signed in to change notification settings - Fork 89
Using options for data
NN--- edited this page Apr 18, 2012
·
3 revisions
- Category: Lists, Tuples and Options
- Description: Here we return an option from a function indicating the opening hours of a shop, if any.
- Code:
using System;
using System.Console;
using Nemerle;
def openingHours(day)
{ // implicit match construction
| DayOfWeek.Monday
| DayOfWeek.Tuesday
| DayOfWeek.Thursday
| DayOfWeek.Friday => Some(9, 17)
| DayOfWeek.Wednesday => Some(9, 19) // extended hours on Wednesday
| _ => None()
}
def today = DateTime.Now.DayOfWeek;
match (openingHours(today))
{
| Some((s, f)) => WriteLine($"The shop's open today from $s:00-$f:00")
| _ => WriteLine("The shop's not open today")
}
- Execution Result (in case of Wednesday):
The shop's open today from 9:00-19:00
- Execution Result (in case of Friday):
The shop's open today from 9:00-17:00
- Execution Result (in other cases)
The shop's not open today
[Copyright ©](Terms of use, legal notice)