Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add '??' overloadable operator #45

Merged
merged 1 commit into from Jan 8, 2020

Conversation

BastianBlokland
Copy link
Owner

Adds ?? as a user overloadable operator.

struct None
union Option{T} = T, None

fun ??{T}(Option{T} o, T default)
  o is T t ? t : default

fun isDigit(char c)
  c >= '0' && c <= '9'

fun parseInt(char c) -> Option{int}
  if isDigit(c) -> int(c) - '0'
  else          -> None()

print(parseInt('3') ?? -1)

@BastianBlokland BastianBlokland merged commit 532a3cf into master Jan 8, 2020
@BastianBlokland BastianBlokland deleted the feature/qmarkqmark-operator branch January 8, 2020 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant