Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
d66659f
Update exercise to new compiler: accumulate
ageron Jun 9, 2026
6223042
Update bin/*, config/*, and docs/* to new Roc
ageron Jun 9, 2026
30ff50e
Replace 'roc format' with 'roc fmt' and format accumulate-test.roc
ageron Jun 9, 2026
6bf2a73
Format Accumulate.roc and its Example.roc
ageron Jun 9, 2026
9438c21
Update exercise to new compiler: acronym
ageron Jun 9, 2026
28f4a81
Format acronym/.meta/Example.roc
ageron Jun 9, 2026
bac505e
Use default platform unless additional libraries are used
ageron Jun 11, 2026
d3fd9b2
Update exercise to new compiler: affine-cipher
ageron Jun 11, 2026
09a2d96
Reorder future builtin functions
ageron Jun 11, 2026
5163814
roc fmt affine-cipher .roc files
ageron Jun 11, 2026
a85d197
Update exercise to new compiler: all-your-base
ageron Jun 11, 2026
5fe5896
Update exercise to new compiler: allergies
ageron Jun 11, 2026
d2afec3
Simplify match
ageron Jun 11, 2026
0d9e336
Update exercise to new compiler: armstrong-numbers
ageron Jun 11, 2026
8047962
Move main! to the end of the *-test.roc files and explain why it does…
ageron Jun 12, 2026
dfd24c7
Update exercise to new compiler: atbash-cipher
ageron Jun 12, 2026
02aeed9
Update exercise to new compiler: binary
ageron Jun 12, 2026
cc50a12
Remove unneeded parentheses
ageron Jun 12, 2026
d4e75a0
Always use the same 'Please implement' message
ageron Jun 12, 2026
22d5c88
Add footer at the end of each template.j2
ageron Jun 12, 2026
6692385
Update exercise to new compiler: circular-buffer
ageron Jun 12, 2026
ac32d80
Upgrade all .meta/template.j2 and *-test.roc files to new compiler
ageron Jun 13, 2026
d2181f0
Fix to_roc_multiline_string Jinja filter, and skip non-dir files in e…
ageron Jun 13, 2026
e493437
Update exercise to new compiler: binary-search
ageron Jun 13, 2026
a4de383
Change Bool.true/false to Bool.True/False
ageron Jun 13, 2026
af94237
Replace Num.log(2), Num.pi, Num.e with float values
ageron Jun 13, 2026
0f199c3
Upgrade modules to the new type module format (first step)
ageron Jun 13, 2026
8300bda
Update exercise to new compiler: bob
ageron Jun 13, 2026
6043ce5
Update exercise to new compiler: bowling
ageron Jun 13, 2026
4e89774
Update exercise to new compiler: change
ageron Jun 13, 2026
99d212a
Update exercise to new compiler: clock
ageron Jun 13, 2026
404cefa
Update exercise to new compiler: collatz-conjecture
ageron Jun 13, 2026
b652e0d
Prefer try+crash rather than wrap
ageron Jun 13, 2026
145de52
Update exercise to new compiler: crypto-square
ageron Jun 14, 2026
66a3bbe
Replace .to() with ..= or ..<
ageron Jun 16, 2026
ecdbd3f
Update exercise to new compiler: binary-search-tree
ageron Jun 16, 2026
a03bac9
Update exercise to new compiler: collatz-conjecture
ageron Jun 16, 2026
87d1cff
Update exercise to new compiler: alphametics (but it triggers a roc bug)
ageron Jun 16, 2026
a75f0fb
Update exercise to new compiler: complex-numbers (but it triggers a r…
ageron Jun 16, 2026
13da63b
Update exercise to new compiler: connect (but it triggers a roc bug)
ageron Jun 16, 2026
4099031
Update exercise to new compiler: hello-world
ageron Jun 16, 2026
a902e09
Update exercise to new compiler: leap
ageron Jun 16, 2026
1b1a27a
Update exercise to new compiler: two-fer
ageron Jun 16, 2026
8a1cbab
Update exercise to new compiler: flatten-array
ageron Jun 17, 2026
4793883
Update exercise to new compiler: eliuds-eggs
ageron Jun 17, 2026
425d91d
Update exercise to new compiler: grains
ageron Jun 17, 2026
e2ad1b9
Update exercise to new compiler: isogram
ageron Jun 17, 2026
7d8ddbe
Update exercise to new compiler: raindrops
ageron Jun 17, 2026
3ced8b7
Update exercise to new compiler: sum-of-multiples
ageron Jun 17, 2026
82962a6
Update exercise to new compiler: high-scores
ageron Jun 17, 2026
cdcbb76
Update exercise to new compiler: pangram
ageron Jun 17, 2026
679727b
Update exercise to new compiler: nucleotide-count
ageron Jun 17, 2026
e05a931
Update exercise to new compiler: secret-handshake
ageron Jun 17, 2026
0dd8650
Update exercise to new compiler: knapsack
ageron Jun 17, 2026
0b14ca7
Update exercise to new compiler: prime-factors
ageron Jun 17, 2026
fbe4c1b
Update exercise to new compiler: proverb
ageron Jun 17, 2026
1921324
Update exercise to new compiler: darts
ageron Jun 17, 2026
0c52c15
Update exercise to new compiler: hamming
ageron Jun 17, 2026
030c8be
Update exercise to new compiler: roman-numerals
ageron Jun 17, 2026
57cdd17
Update exercise to new compiler: rotational-cipher
ageron Jun 17, 2026
116b49d
Update exercise to new compiler: etl
ageron Jun 17, 2026
914100f
Update exercise to new compiler: square-root
ageron Jun 17, 2026
7431e5d
Update exercise to new compiler: difference-of-squares
ageron Jun 17, 2026
8b9b733
Update exercise to new compiler: resistor-color
ageron Jun 17, 2026
f024936
Update exercise to new compiler: series
ageron Jun 17, 2026
1526a07
Update exercise to new compiler: sieve
ageron Jun 17, 2026
09ce243
Add comment about issue 9690
ageron Jun 17, 2026
12c5941
Update exercise to new compiler: triangle
ageron Jun 18, 2026
8d8ed7b
Update exercise to new compiler: rna-transcription
ageron Jun 18, 2026
df690b7
Update exercise to new compiler: transpose
ageron Jun 18, 2026
7fd090e
Update exercise to new compiler: pascals-triangle
ageron Jun 18, 2026
8560813
Update exercise to new compiler: pythagorean-triplet
ageron Jun 18, 2026
afb46db
Update exercise to new compiler: matching-brackets
ageron Jun 18, 2026
edc08ba
Update exercise to new compiler: octal
ageron Jun 18, 2026
ac6a2b3
Update exercise to new compiler: diamond
ageron Jun 18, 2026
06e7ed3
Update exercise to new compiler: perfect-numbers
ageron Jun 18, 2026
f762954
Update exercise to new compiler: hexadecimal
ageron Jun 18, 2026
97d0eb7
Update exercise to new compiler: killer-sudoku-helper
ageron Jun 18, 2026
c939b05
Update exercise to new compiler: largest-series-product
ageron Jun 18, 2026
a51f403
Fix error in sum-of-multiples
ageron Jun 18, 2026
389e5af
Update exercise to new compiler: strain
ageron Jun 18, 2026
de76368
Update exercise to new compiler: isbn-verifier
ageron Jun 18, 2026
0115806
Update exercise to new compiler: nth-prime
ageron Jun 18, 2026
2d6c4fb
Update exercise to new compiler: phone-number
ageron Jun 18, 2026
5501ca6
Update exercise to new compiler: sublist
ageron Jun 18, 2026
56958c1
Update exercise to new compiler: queen-attack
ageron Jun 18, 2026
736251c
Update exercise to new compiler: house
ageron Jun 18, 2026
997b697
Update exercise to new compiler: spiral-matrix
ageron Jun 18, 2026
55a58a5
Update exercise to new compiler: resistor-color-duo
ageron Jun 18, 2026
1aec3af
Update exercise to new compiler: scrabble-score
ageron Jun 18, 2026
5707d54
Update exercise to new compiler: matrix
ageron Jun 18, 2026
78a315f
Update exercise to new compiler: space-age
ageron Jun 18, 2026
5af9b48
Update exercise to new compiler: kindergarten-garden
ageron Jun 18, 2026
38f7f86
Update exercise to new compiler: protein-translation
ageron Jun 18, 2026
90db856
Update exercise to new compiler: wordy
ageron Jun 18, 2026
3b34f63
Update exercise to new compiler: robot-simulator
ageron Jun 18, 2026
f4ecb4c
Update exercise to new compiler: variable-length-quantity
ageron Jun 18, 2026
1c80b59
Remove specific errors from affine-cipher exercise stub
ageron Jun 19, 2026
8fd010f
Update exercise to new compiler: luhn
ageron Jun 19, 2026
642a5e8
Update exercise to new compiler: saddle-points
ageron Jun 19, 2026
cb33966
Update exercise to new compiler: word-count
ageron Jun 19, 2026
9f4ebf2
Update exercise to new compiler: pig-latin
ageron Jun 19, 2026
e35f87a
Update exercise to new compiler: run-length-encoding
ageron Jun 19, 2026
eb118ba
Update exercise to new compiler: dominoes
ageron Jun 19, 2026
3fb6b94
Update exercise to new compiler: rail-fence-cipher
ageron Jun 19, 2026
4bcb588
Update exercise to new compiler: flower-field
ageron Jun 20, 2026
03a039e
Update exercise to new compiler: minesweeper
ageron Jun 20, 2026
b866a79
Update exercise to new compiler: yacht
ageron Jun 20, 2026
5234778
Update exercise to new compiler: rectangles
ageron Jun 20, 2026
4f41d8d
Update exercise to new compiler: palindrome-products
ageron Jun 20, 2026
66256e8
Update exercise to new compiler: food-chain
ageron Jun 20, 2026
b84f37d
Update exercise to new compiler: error-handling
ageron Jun 20, 2026
6ca60fc
Update exercise to new compiler: custom-set
ageron Jun 20, 2026
d7074ff
Update exercise to new compiler: list-ops
ageron Jun 20, 2026
f713c3b
Remove Temp.roc
ageron Jun 20, 2026
c48ca5e
Upgrade to latest roc version and fix a few minor issues
ageron Jun 20, 2026
61c2095
Update exercise to new compiler: say
ageron Jun 20, 2026
b2c8284
Update exercise to new compiler: word-search
ageron Jun 20, 2026
d173ab5
Update exercise to new compiler: ocr-numbers
ageron Jun 20, 2026
ace6f65
Merge remote-tracking branch 'upstream/main' into migrate-to-zig-comp…
ageron Jun 21, 2026
1daeb1a
Update exercise to new compiler: two-bucket
ageron Jun 21, 2026
a40b753
Update exercise to new compiler: simple-linked-list
ageron Jun 21, 2026
bde2f9c
Update the exercise stub for simple-linked-list
ageron Jun 21, 2026
0e7604f
Remove old test file for simple-linked-list
ageron Jun 21, 2026
443744a
List.rev is now available
ageron Jun 21, 2026
e3b5f1b
Avoid using ?? when it can silently fail
ageron Jun 21, 2026
77fcf87
Replace external library URL with TODO
ageron Jun 21, 2026
6ec49aa
Simplify the game_with_previous_rolls function by using vars
ageron Jun 21, 2026
8f4f3a8
Replace [1,2,3]->find(2) with find([1,2,3], 2) to reduce surprise for…
ageron Jun 21, 2026
4e687a0
Replace coins->find_fewest_coins(1) with find_fewest_coins(coins, 1) …
ageron Jun 21, 2026
91adcde
Update to cli platform 0.8, and replace external libraries with TODO …
ageron Jun 21, 2026
c3ab56a
Fix complex-numbers
ageron Jun 21, 2026
78a2417
Work around issue #9742
ageron Jun 22, 2026
0c313cb
Simplify nth-prime solution
ageron Jun 22, 2026
ef7a068
Update exercise to new compiler: forth
ageron Jun 22, 2026
3c0fce9
Update exercise to new compiler: go-counting
ageron Jun 22, 2026
993b377
Clean up circular-buffer test formatting
ageron Jun 22, 2026
6a6f336
Add new tests in 'connect' exercise
ageron Jun 22, 2026
cf39c75
Update flower-field tests (adds a new test)
ageron Jun 22, 2026
f9be238
Update isbn-verifier tests (adds two tests)
ageron Jun 22, 2026
7d749f0
Update perfect-numbers tests (adds one test)
ageron Jun 22, 2026
78818dc
Regenerated tests
ageron Jun 22, 2026
2c25cc8
Update tests.toml for connect, flower-field, isbn-verifier, perfect-n…
ageron Jun 22, 2026
62d49ca
Fix type in markdown formatting in list-ops/.docs/instructions.append.md
ageron Jun 22, 2026
b9ac45b
Clarify TODO in simple-linked-list-test.roc regarding issue 9743
ageron Jun 22, 2026
5270b94
Update exercise to new compiler: grep
ageron Jun 22, 2026
83dd838
Update exercise to new compiler: poker
ageron Jun 22, 2026
b2eaaa1
Update exercise to new compiler: tournament
ageron Jun 22, 2026
ab237cc
Update exercise to new compiler: zebra-puzzle
ageron Jun 22, 2026
e4e03cc
Update exercise to new compiler: rational-numbers
ageron Jun 22, 2026
af46d92
Update protein-translation since issue 9700 was resolved
ageron Jun 22, 2026
5aafb87
Upgrade to roc-platform-template-zig version 0.9
ageron Jun 22, 2026
bf3cbb8
Add TODO regarding issue 9753
ageron Jun 22, 2026
b3cd07b
Fix Err `Err "..."` to `Err("...")`
ageron Jun 23, 2026
402e195
Migrate errorMessage to error_message
ageron Jun 23, 2026
b8789d7
Replace ComplexNumbers.Complex with simply Complex, and replace metho…
ageron Jun 23, 2026
9eaa627
Replace `complex` with `new` and add a few comments
ageron Jun 23, 2026
eb68522
Fix type and replace ???? with ...
ageron Jun 23, 2026
4886728
Shorten imaginary to imag, and replace new(a,b) with new({real: a, im…
ageron Jun 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
11 changes: 6 additions & 5 deletions bin/add-exercise
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ cat << END_TEST > "exercises/practice/${slug}/${slug}-test.roc"
END_TEST

cat << END_STUB > "exercises/practice/${slug}/${slug_pascal}.roc"
module [${slug_camel}]

${slug_camel} = |my_arg|
crash "Please implement the '${slug_camel}' function"
${slug_pascal} :: {}.{
${slug_camel} = |my_arg| {
crash "Please implement the '${slug_camel}' function"
}
}
END_STUB

cp "exercises/practice/${slug}/${slug_pascal}.roc" "exercises/practice/${slug}/.meta/Example.roc"
Expand All @@ -107,7 +108,7 @@ Your next steps are:
- Create the example solution in 'exercises/practice/${slug}/.meta/Example.roc'
- Verify the example solution by running 'bin/verify-exercises ${slug}'
- Edit the stub solution in 'exercises/practice/${slug}/${slug_pascal}.roc'
- Format all your Roc code by running 'roc format' on each .roc file
- Format all your Roc code by running 'roc fmt' on each .roc file
- Update the 'difficulty' value for the exercise's entry in the 'config.json' file
- Validate CI using 'bin/configlet lint' and 'bin/configlet fmt'
NEXT_STEPS
Expand Down
17 changes: 10 additions & 7 deletions bin/generate_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ def to_roc_multiline_string(lines: Union[str, List[str]]) -> str:
elif len(lines) == 1:
return to_roc_string(lines[0])
else:
return "\n".join(
["", '"""'] + [escape_roc_string_content(line) for line in lines] + ['"""']
).replace("$(", "\\$(")
return "\n" + "\n".join(
[r'\\' + escape_roc_string_content(line) for line in lines]
).replace("${", r"\${") + "\n"


def to_roc_tuple(values: Any):
Expand All @@ -177,7 +177,7 @@ def to_roc_record(obj: Dict[str, Any]):


def to_roc_bool(value: bool):
return "Bool.true" if value else "Bool.false"
return "Bool.True" if value else "Bool.False"


def to_roc_list(values: Any):
Expand All @@ -187,7 +187,7 @@ def to_roc_list(values: Any):

def to_roc_float(value: Union[int, float]):
value = float(value)
return f"{value!r}f64".replace("+", "")
return f"{value!r}.F64".replace("+", "")


def to_roc(value: Any) -> str:
Expand Down Expand Up @@ -377,9 +377,10 @@ def load_additional_tests(exercise: Path) -> List[TypeJSON]:

def format_file(path: Path) -> NoReturn:
"""
Runs roc format on file at path
Runs roc fmt on file at path
"""
subprocess.check_call(["roc", "format", path])
subprocess.check_call(["roc", "fmt", path])
pass


def drop_timestamp(lines):
Expand Down Expand Up @@ -567,6 +568,8 @@ def generate(
env.tests["error_case"] = error_case
result = True
for exercise in sorted(Path("exercises/practice").glob(exercise_glob)):
if not exercise.is_dir():
continue
if not generate_exercise(env, spec_path, exercise, check):
result = False
if stop_on_failure:
Expand Down
9 changes: 4 additions & 5 deletions bin/install-roc
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@

function download_alpha_release() {
local install_dir="${1}"
local install_file="${install_dir}/roc.tar.gz"
local release_url="https://github.com/roc-lang/roc/releases/download/alpha4-rolling/roc-linux_x86_64-alpha4-rolling.tar.gz"
rm -rf "${install_dir}"
mkdir -p "${install_dir}"
wget -q -O ${install_file} ${release_url}
tar -xzf "${install_file}" -C "${install_dir}" --strip-components 1
rm -f "${install_file}"
cd "${install_dir}"
wget --secure-protocol=TLSv1_2 -qO- https://roc-lang.org/install_roc.sh | ROC_CONTINUE_IF_STALE=y ROC_ADD_TO_PATH=n sh
ln -s roc_nightly*/roc roc
}

function update_shell {
Expand Down
24 changes: 13 additions & 11 deletions config/generator_macros.j2
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,29 @@

{% macro header(imports=[], ignore=[]) -%}

app [main!] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.20.0/X73hGh05nNTkDHU06FHC0YfFaQB1pimX7gncRcao5mU.tar.br"
{%- if imports -%}
app [main!] {
pf: platform "https://github.com/lukewilliamboswell/roc-platform-template-zig/releases/download/0.9/8GdFEvQYS3TeAZxKvTzCLVdQiomweGtXcdZkXNDEeABq.tar.zst"
{%- for name in imports -%},
{% if name == "unicode" -%}
unicode: "https://github.com/roc-lang/unicode/releases/download/0.3.0/9KKFsA4CdOz0JIOL7iBSI_2jGIXQ6TsFBXgd086idpY.tar.br"
unicode: "https://github.com/roc-lang/unicode/..." # TODO: update when a zig-compatible release is available
{%- elif name == "isodate" -%}
isodate: "https://github.com/imclerran/roc-isodate/releases/download/v0.6.2/73w_H-aSJNcWqtXvMG4JQw_HoaApMBLnE92XD4OcVGU.tar.br"
isodate: "https://github.com/imclerran/roc-isodate/..." # TODO: update when a zig-compatible release is available
{%- elif name == "json" -%}
json: "https://github.com/lukewilliamboswell/roc-json/releases/download/0.13.0/RqendgZw5e1RsQa3kFhgtnMP8efWoqGRsAvubx4-zus.tar.br"
json: "https://github.com/lukewilliamboswell/roc-json/..." # TODO: update when a zig-compatible release is available
{%- elif name == "parser" -%}
parser: "https://github.com/lukewilliamboswell/roc-parser/releases/download/0.10.0/6eZYaXkrakq9fJ4oUc0VfdxU1Fap2iTuAN18q9OgQss.tar.br"
parser: "https://github.com/lukewilliamboswell/roc-parser/..." # TODO: update when a zig-compatible release is available
{%- endif -%}
{%- endfor -%}
{%- endif %}
{%- endfor %}
}

import pf.Stdout
{%- endif %}
{%- endmacro %}

main! = |_args|
Stdout.line!("")
{% macro footer() -%}

{%- endmacro %}
# This program is only used to run tests with `roc test`, so main! does nothing.
main! = |_args| { Ok({}) }

{%- endmacro %}
28 changes: 14 additions & 14 deletions docs/SNIPPET.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
app [main!] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.20.0/X73hGh05nNTkDHU06FHC0YfFaQB1pimX7gncRcao5mU.tar.br" }

import pf.Stdout

factorial = |number|
when number is
1 -> 1
n -> n * factorial (n - 1)

expect factorial 5 == 1 * 2 * 3 * 4 * 5

main! = |_args|
result = factorial 20 |> Num.to_str
Stdout.line! "factorial 20 = ${result}"
factorial = |number| {
match number {
1 => 1
n => n * factorial(n - 1)
}
}

expect factorial(5) == 1 * 2 * 3 * 4 * 5

main! = |_args| {
result = factorial(20)
echo!("factorial 20 = ${result.to_str()}")
Ok({})
}
4 changes: 2 additions & 2 deletions docs/TESTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ roc test hello-world-test.roc
If you've solved the exercise, you should see 0 failed tests, for example:

```
0 failed and 1 passed in 583 ms.
All (5) tests passed in 123.4 ms.
```

However, if your code has any errors, they will look like this:
Expand All @@ -36,7 +36,7 @@ This expectation failed:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


1 failed and 0 passed in 1264 ms.
1 failed and 0 passed in 123.4 ms.
```

This should help you fix your code. Once your code works, you can submit it using the `exercism submit` command (see `HELP.md` in the exercise directory for more details).
24 changes: 12 additions & 12 deletions exercises/practice/accumulate/.meta/Example.roc
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module [accumulate]

accumulate : List a, (a -> b) -> List b
accumulate = |list, func|
help = |output, input|
when input is
[] -> output
[first, .. as rest] ->
List.append(output, func(first))
|> help(rest)

help([], list)
Accumulate :: {}.{
accumulate : List(a), (a -> b) -> List(b)
accumulate = |list, func| {
help = |output, input| {
match input {
[] => output
[first, .. as rest] => output.append(func(first))->help(rest)
}
}
help([], list)
}
}
51 changes: 29 additions & 22 deletions exercises/practice/accumulate/.meta/template.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,43 @@
import {{ exercise | to_pascal }} exposing [{{ cases[0]["property"] | to_snake }}]

{% set accumulators = {
"(x) => x * x": "|x|\n x * x",
"(x) => x * x": "|x| { x * x }",
"(x) => upcase(x)": "to_upper",
"(x) => reverse(x)": "reverse",
"(x) => accumulate([\"1\", \"2\", \"3\"], (y) => x + y)": "|x|\n accumulate([\"1\", \"2\", \"3\"], |y| Str.concat(x, y))"
"(x) => reverse(x)": "str_reverse",
"(x) => accumulate([\"1\", \"2\", \"3\"], (y) => x + y)": "|x| {\n accumulate([\"1\", \"2\", \"3\"], |y| { Str.concat(x, y) })\n }"
} -%}

{% for case in cases -%}
# {{ case["description"] }}
expect
expect {
result = {{ case["property"] | to_snake }}({{ case["input"]["list"] | to_roc }}, {{ accumulators[case["input"]["accumulator"]] }})
result == {{ case["expected"] | to_roc }}
}

{% endfor %}
{% endfor -%}

reverse : Str -> Str
reverse = |str|
Str.to_utf8(str)
|> List.reverse
|> Str.from_utf8
|> Result.with_default("")

to_upper_char : U8 -> U8
to_upper_char = |byte| {
if 'a' <= byte and byte <= 'z' {
byte - 'a' + 'A'
} else {
byte
}
}

to_upper : Str -> Str
to_upper = |str|
Str.to_utf8(str)
|> List.map(
|byte|
if 'a' <= byte && byte <= 'z' then
byte - 'a' + 'A'
else
byte
)
|> Str.from_utf8
|> Result.with_default("")
to_upper = |str| {
str.to_utf8().map(to_upper_char)->Str.from_utf8() ?? ""
}

str_reverse : Str -> Str
str_reverse = |str| {
str
.to_utf8()
.rev()
->Str.from_utf8()
?? ""
}

{{ macros.footer() }}
11 changes: 6 additions & 5 deletions exercises/practice/accumulate/Accumulate.roc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module [accumulate]

accumulate : List a, (a -> b) -> List b
accumulate = |list, func|
crash("Please implement 'accumulate'")
Accumulate :: {}.{
accumulate : List(a), (a -> b) -> List(b)
accumulate = |list, func| {
crash "Please implement the 'accumulate' function"
}
}
Loading
Loading