Error handling
MatheusRich opened this issue · 0 comments
MatheusRich commented
V's error handling seems to be a good fit here.
This would play nicely with the idea of "soft-typing" (i.e. world's laziest type checker):
User = {
db = [{id: 1, name "Matz"}, {id: 2, name "Matheus"}]
# The ! here means it may fail
find! = fn { |id|
List.each(db, fn { |user|
if user.id == id { return user; }
});
return none; # or return error("msg")
}
}
User.find!(3) or { {id: 0, name "Dummy user"} }