|
|
|
|
|
by bonquesha99
2741 days ago
|
|
Thanks! Agreed it feels like a good fit for Ruby as well! RE the pattern matching stuff I think the destructuring concept could be applied to look something like: def div(*args)
case args
when Pattern{[a, 0]} then [:error, "can't divide by 0"]
when Pattern{[a, 1]} then [:ok, Pattern.last.a]
when Pattern{[0, b]} then [:ok, 0]
when Pattern{[a, b]} then [:ok, Pattern.last.a / Pattern.last.b]
end
end
def something(object)
case object
when Pattern{a[b, c]} then [:ok, Pattern.last.b + Pattern.last.c]
else [:error, "a didn't contain b and c"]
end
end
Some shorthand to access `Pattern.last` e.g. "$~" for regex would make things even nicer! |
|