On Fri, May 4, 2018 at 5:02 AM, Robert Roskam
Hey Chris,
Thanks for bringing that up! Before submitting this, I actually had the syntax for multiple matches for one arm being separated by or. And frankly I just didn't like how that looked for more than 3 items:
'1' or '2' or '3' or '4' or '5' vs '1', '2', '3', '4', '5'
But you're right. The syntax should be for tuples instead.
Agreed.
Here's my revised syntax, using a guard instead for the moment:
def convert_time_to_timedelta_with_match(unit:str, amount:int, now:date): return match unit: x if x in ('days', 'hours', 'weeks') => timedelta(**{unit: amount}) 'months' => timedelta(days=30 * amount) 'years' => timedelta(days=365 * amount) 'cal_years' => now - now.replace(year=now.year - amount)
And then this comes down to the same as all the other comparisons -
the "x if x" gets duplicated. So maybe it would be best to describe
this thus:
match <expr> :
<expr> | (