diff --git a/examples/functions/calculator.own b/examples/functions/calculator.own new file mode 100644 index 0000000..571cbe8 --- /dev/null +++ b/examples/functions/calculator.own @@ -0,0 +1,46 @@ +// Simple parser example +use "std" +use "types" + +operations = { + "+" : def(a,b) = a+b, + "-" : def(a,b) = a-b, + "*" : def(a,b) = a*b, + "/" : def(a,b) = a/b, + "%" : def(a,b) = a%b, + ">" : def(a,b) = a>b, + "<" : def(a,b) = a4") \ No newline at end of file diff --git a/examples/functions/chain.own b/examples/functions/chain.own new file mode 100644 index 0000000..cf8ac83 --- /dev/null +++ b/examples/functions/chain.own @@ -0,0 +1,10 @@ +use "functional" + +data = [1,2,3,4,5,6,7,8,9] +chain(data, + ::filter, def(x) = x % 2 == 0, + ::map, def(x) = [x, x * x, x * x * x], + ::sortby, def(x) = -x[2], + ::foreach, ::echo +) + diff --git a/examples/network/telegram_api.own b/examples/network/telegram_api.own new file mode 100644 index 0000000..6619d28 --- /dev/null +++ b/examples/network/telegram_api.own @@ -0,0 +1,36 @@ +use "std" +use "http" +use "json" +use "functional" + +// Telegram API example + +token = "YOUR_TOKEN" + +def toParams(obj) { + str = "" + for k, v : obj + str += k + "=" + v + "&" + return str +} +def createRawUrl(method, params, token = "") = "https://api.telegram.org/bot" + token + "/" + method + "?"+params+"access_token="+token +def createUrl(method, params, token = "") = createRawUrl(method, toParams(params), token) +def invokeJson(method, params, callback) = http(createUrl(method, params, token), combine(::jsondecode, callback)) +def invoke(method, params, callback) = http(createUrl(method, params, token), callback) + +def sendMessage(text = "", chatId = 1) { + invoke("sendMessage", { + "chat_id": chatId, + "text": text + }, ::echo) +} + +def getUpdates() = invoke("getUpdates", {}, ::echo) + + +// Get updates in chat +getUpdates() +// Send message to chatId 1 +sendMessage("Hello", 1) +// Send message to channel +sendMessage("Hello", "@telegram_channel") \ No newline at end of file