Skip to content

Instantly share code, notes, and snippets.

@thosakwe
Last active October 27, 2016 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thosakwe/4df38c7fd1fe5caf30b33e0a0b097e5d to your computer and use it in GitHub Desktop.
Save thosakwe/4df38c7fd1fe5caf30b33e0a0b097e5d to your computer and use it in GitHub Desktop.
Hypothetical funclang
use <filter> as only
use <func> as F
use [Input] of <io>
fn fib(n) {
ret F.decide({
n <= 1 : () => n
}).else(() => F.sum([
fib(n - 1),
fib(n - 2)
]));
}
fn main() {
ret new Input()
.filter(only.int)
.once(n => {
print('The %nth Fibonacci number is %{fib(n)}.')
});
}
use <func> as F
main() =>
F.for([1..100])
.map(n => F.decide({
n % 3 && n % 5 : () => 'FizzBuzz',
n % 3 : 'Fizz',
n % 5 : 'Buzz'
}).else(() => n)
.all(print)
use <func> as F
use <regex>
main() =>
F.src('I have 69 cats, drive 3 cars and own 12 houses.')
.morph(rgx('[0-9]+', ['g']))
.morph(match => match[0])
.morph(group => 'You have %group cat(s)???')
.pass(print);
use <regex>
main() {
let matcher = rgx('[0-9]+', ['g']);
let match = matcher('I have 69 cats, drive 3 cars and own 12 houses.');
print('You have %{match[0]} cat(s)???');
}
use <func> as F
use <task>
main() {
let tasks = [
new Task.value(1),
new Task.immediate(() => 2),
new Task(() => 3)
];
ret F.streams(F.map(tasks, task => task.stream)).once(print);
}
use <task>
main() {
let task = new Task.value(1337);
ret task.stream.once(n => {
print('Value from task: %n');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment