forked from Orchid/orchid
Extended examples
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import system::(io, fs, async)
|
import system::(io, fs, async)
|
||||||
import std::(to_string, to_uint, inspect)
|
import std::(to_string, to_uint, inspect)
|
||||||
|
|
||||||
const folder_view := \path. \next. do{
|
const folder_view := (path, next) => do{
|
||||||
cps println $ "Contents of " ++ fs::os_print path;
|
cps println $ "Contents of " ++ fs::os_print path;
|
||||||
cps entries = async::block_on $ fs::read_dir path;
|
cps entries = async::block_on $ fs::read_dir path;
|
||||||
cps list::enumerate entries
|
cps list::enumerate entries
|
||||||
|
|||||||
16
examples/fizz-buzz/main.orc
Normal file
16
examples/fizz-buzz/main.orc
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import std::to_string
|
||||||
|
|
||||||
|
const fizz_buzz := n => (
|
||||||
|
(recursive r (i=0) list::cons i $ r (i + 1))
|
||||||
|
|> list::map (i =>
|
||||||
|
if i % 15 == 0 then "FizzBuzz"
|
||||||
|
else if i % 3 == 0 then "Fizz"
|
||||||
|
else if i % 5 == 0 then "Buzz"
|
||||||
|
else to_string i
|
||||||
|
)
|
||||||
|
|> list::take n
|
||||||
|
|> list::reduce ((l, r) => l ++ "\n" ++ r)
|
||||||
|
|> option::unwrap
|
||||||
|
)
|
||||||
|
|
||||||
|
const main := fizz_buzz 100
|
||||||
@@ -6,7 +6,7 @@ export const main := do{
|
|||||||
let sum = bar
|
let sum = bar
|
||||||
|> list::skip 2
|
|> list::skip 2
|
||||||
|> list::take 3
|
|> list::take 3
|
||||||
|> list::reduce (\a. \b. a + b)
|
|> list::reduce ((a, b) => a + b)
|
||||||
|> option::unwrap;
|
|> option::unwrap;
|
||||||
cps println $ to_string sum;
|
cps println $ to_string sum;
|
||||||
0
|
0
|
||||||
|
|||||||
Reference in New Issue
Block a user