Last active
December 10, 2015 18:39
-
-
Save azenla/a579d4c7c063869efd96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Socket { | |
property host: String | |
property port: Integer | |
emits @connected: Socket | |
emits @data: any | |
constructor(self.host, self.port) | |
function connect() -> void { | |
@connected <- self | |
} | |
operator <-(data: any) = @data <- data | |
@data(data: any) { | |
print(data) | |
} | |
} | |
let socket = Socket("google.com", 80) | |
socket@connected { e -> | |
print("Connected!") | |
socket <- "Hello World" | |
} | |
socket.connect() | |
if socket is Socket { | |
print("Object is a Socket") | |
} | |
if socket has connect() { | |
print("Socket has a connect() method") | |
} | |
let list = [1, 2, 3] | |
list@changed { e -> | |
if e.isAddEvent { | |
print("Added $(e.value)") | |
} | |
} | |
list <- 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment