Browse Source

Exercism: Accumulate

master
Julio Biason 3 years ago
parent
commit
4e2e2c9fe9
  1. 30
      erlang/accumulate/.exercism/config.json
  2. 1
      erlang/accumulate/.exercism/metadata.json
  3. 36
      erlang/accumulate/HELP.md
  4. 51
      erlang/accumulate/README.md
  5. 30
      erlang/accumulate/rebar.config
  6. 9
      erlang/accumulate/src/accumulate.app.src
  7. 8
      erlang/accumulate/src/accumulate.erl
  8. 30
      erlang/accumulate/test/accumulate_tests.erl

30
erlang/accumulate/.exercism/config.json

@ -0,0 +1,30 @@
{
"blurb": "Implement the `accumulate` operation, which, given a collection and an operation to perform on each element of the collection, returns a new collection containing the result of applying that operation to each element of the input collection.",
"authors": [],
"contributors": [
"adolfopa",
"ErikSchierboom",
"etrepum",
"iHiD",
"JordanAdams",
"juhlig",
"kytrinyx",
"magthe",
"NobbZ",
"tmcgilchrist",
"xymbol"
],
"files": {
"solution": [
"src/accumulate.erl"
],
"test": [
"test/accumulate_tests.erl"
],
"example": [
".meta/example.erl"
]
},
"source": "Conversation with James Edward Gray II",
"source_url": "https://twitter.com/jeg2"
}

1
erlang/accumulate/.exercism/metadata.json

@ -0,0 +1 @@
{"track":"erlang","exercise":"accumulate","id":"c9819e2454fa472d881c797983106708","url":"https://exercism.org/tracks/erlang/exercises/accumulate","handle":"JBiason","is_requester":true,"auto_approve":false}

36
erlang/accumulate/HELP.md

@ -0,0 +1,36 @@
# Help
## Running the tests
You can run the tests by running the following command from the exercise directory.
```bash
$ rebar3 eunit
```
## Submitting your solution
You can submit your solution using the `exercism submit src/accumulate.erl` command.
This command will upload your solution to the Exercism website and print the solution page's URL.
It's possible to submit an incomplete solution which allows you to:
- See how others have completed the exercise
- Request help from a mentor
## Need to get help?
If you'd like help solving the exercise, check the following pages:
- The [Erlang track's documentation](https://exercism.org/docs/tracks/erlang)
- [Exercism's support channel on gitter](https://gitter.im/exercism/support)
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
To get help if you're having trouble, you can use one of the following resources:
- [Exercism related BEAM support channel on gitter](https://gitter.im/exercism/xerlang)
- [Erlang Documentation](http://www.erlang.org/doc.html)
- [Learn You Some Erlang for Great Good](http://learnyousomeerlang.com)
- [StackOverflow](http://stackoverflow.com/)

51
erlang/accumulate/README.md

@ -0,0 +1,51 @@
# Accumulate
Welcome to Accumulate on Exercism's Erlang Track.
If you need help running the tests or submitting your code, check out `HELP.md`.
## Instructions
Implement the `accumulate` operation, which, given a collection and an
operation to perform on each element of the collection, returns a new
collection containing the result of applying that operation to each element of
the input collection.
Given the collection of numbers:
- 1, 2, 3, 4, 5
And the operation:
- square a number (`x => x * x`)
Your code should be able to produce the collection of squares:
- 1, 4, 9, 16, 25
Check out the test suite to see the expected function signature.
## Restrictions
Keep your hands off that collect/map/fmap/whatchamacallit functionality
provided by your standard library!
Solve this one yourself using other basic tools instead.
## Source
### Contributed to by
- @adolfopa
- @ErikSchierboom
- @etrepum
- @iHiD
- @JordanAdams
- @juhlig
- @kytrinyx
- @magthe
- @NobbZ
- @tmcgilchrist
- @xymbol
### Based on
Conversation with James Edward Gray II - https://twitter.com/jeg2

30
erlang/accumulate/rebar.config

@ -0,0 +1,30 @@
%% Erlang compiler options
{erl_opts, [debug_info, warnings_as_errors]}.
{deps, [{erl_exercism, "0.1.2"}]}.
{dialyzer, [
{warnings, [underspecs, no_return]},
{get_warnings, true},
{plt_apps, top_level_deps}, % top_level_deps | all_deps
{plt_extra_apps, []},
{plt_location, local}, % local | "/my/file/name"
{plt_prefix, "rebar3"},
{base_plt_apps, [stdlib, kernel, crypto]},
{base_plt_location, global}, % global | "/my/file/name"
{base_plt_prefix, "rebar3"}
]}.
%% eunit:test(Tests)
{eunit_tests, []}.
%% Options for eunit:test(Tests, Opts)
{eunit_opts, [verbose]}.
%% == xref ==
{xref_warnings, true}.
%% xref checks to run
{xref_checks, [undefined_function_calls, undefined_functions,
locals_not_used, exports_not_used,
deprecated_function_calls, deprecated_functions]}.

9
erlang/accumulate/src/accumulate.app.src

@ -0,0 +1,9 @@
{application, accumulate,
[{description, "exercism.io - accumulate"},
{vsn, "0.0.0"},
{modules, []},
{registered, []},
{applications, [kernel,
stdlib]},
{env, []}
]}.

8
erlang/accumulate/src/accumulate.erl

@ -0,0 +1,8 @@
-module(accumulate).
-export([accumulate/2]).
accumulate(Fn, [H|T]) ->
[Fn(H) | accumulate(Fn, T)];
accumulate(_Fn, []) ->
[].

30
erlang/accumulate/test/accumulate_tests.erl

@ -0,0 +1,30 @@
-module(accumulate_tests).
-include_lib("erl_exercism/include/exercism.hrl").
-include_lib("eunit/include/eunit.hrl").
accumulate_empty_list_test() ->
Fn = fun() -> ok end,
Ls = [],
?assertEqual([], accumulate:accumulate(Fn, Ls)).
accumulate_squares_test() ->
Fn = fun(Number) -> Number * Number end,
Ls = [1, 2, 3],
?assertEqual([1, 4, 9], accumulate:accumulate(Fn, Ls)).
accumulate_upcases_test() ->
Fn = fun(Word) -> string:to_upper(Word) end,
Ls = string:tokens("hello world", " "),
?assertEqual(["HELLO", "WORLD"], accumulate:accumulate(Fn, Ls)).
accumulate_reversed_strings_test() ->
Fn = fun(Word) -> lists:reverse(Word) end,
Ls = string:tokens("the quick brown fox etc", " "),
?assertEqual(["eht", "kciuq", "nworb", "xof", "cte"], accumulate:accumulate(Fn, Ls)).
accumulate_recursively_test() ->
Chars = string:tokens("a b c", " "),
Nums = string:tokens("1 2 3", " "),
Fn = fun(Char) -> [Char ++ Num || Num <- Nums] end,
?assertEqual([["a1", "a2", "a3"], ["b1", "b2", "b3"], ["c1", "c2", "c3"]], accumulate:accumulate(Fn, Chars)).
Loading…
Cancel
Save