Last active
October 27, 2016 18:33
-
-
Save thosakwe/4df38c7fd1fe5caf30b33e0a0b097e5d to your computer and use it in GitHub Desktop.
Hypothetical funclang
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
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)}.') | |
}); | |
} |
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
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) |
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
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); |
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
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)???'); | |
} |
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
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); | |
} |
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
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