diff options
| author | Nathan Perry <np@nathanperry.dev> | 2020-01-28 16:06:48 -0500 |
|---|---|---|
| committer | Nathan Perry <np@nathanperry.dev> | 2020-01-28 16:06:48 -0500 |
| commit | 5dadc47eb07be076a8b270458badb9d8cd7dfead (patch) | |
| tree | 69918ab33ded1e98905ebdf99c6f88f373a7a396 /apps/util | |
| parent | dde5eb52706a9ca8ee257a6cbd75e243582d0a86 (diff) | |
start elixir conversion
Diffstat (limited to 'apps/util')
| -rw-r--r-- | apps/util/.formatter.exs | 4 | ||||
| -rw-r--r-- | apps/util/.gitignore | 24 | ||||
| -rw-r--r-- | apps/util/README.md | 21 | ||||
| -rw-r--r-- | apps/util/lib/thulani/util.ex | 2 | ||||
| -rw-r--r-- | apps/util/lib/thulani/util/compose.ex | 13 | ||||
| -rw-r--r-- | apps/util/lib/thulani/util/curry.ex | 16 | ||||
| -rw-r--r-- | apps/util/mix.exs | 27 | ||||
| -rw-r--r-- | apps/util/test/test_helper.exs | 1 | ||||
| -rw-r--r-- | apps/util/test/thulani/util_test.exs | 4 |
9 files changed, 112 insertions, 0 deletions
diff --git a/apps/util/.formatter.exs b/apps/util/.formatter.exs new file mode 100644 index 0000000..d2cda26 --- /dev/null +++ b/apps/util/.formatter.exs @@ -0,0 +1,4 @@ +# Used by "mix format" +[ + inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] +] diff --git a/apps/util/.gitignore b/apps/util/.gitignore new file mode 100644 index 0000000..d8dbee4 --- /dev/null +++ b/apps/util/.gitignore @@ -0,0 +1,24 @@ +# The directory Mix will write compiled artifacts to. +/_build/ + +# If you run "mix test --cover", coverage assets end up here. +/cover/ + +# The directory Mix downloads your dependencies sources to. +/deps/ + +# Where third-party dependencies like ExDoc output generated docs. +/doc/ + +# Ignore .fetch files in case you like to edit your project deps locally. +/.fetch + +# If the VM crashes, it generates a dump, let's ignore it too. +erl_crash.dump + +# Also ignore archive artifacts (built via "mix archive.build"). +*.ez + +# Ignore package tarball (built via "mix hex.build"). +util-*.tar + diff --git a/apps/util/README.md b/apps/util/README.md new file mode 100644 index 0000000..4b69d4c --- /dev/null +++ b/apps/util/README.md @@ -0,0 +1,21 @@ +# Thulani.Util + +**TODO: Add description** + +## Installation + +If [available in Hex](https://hex.pm/docs/publish), the package can be installed +by adding `util` to your list of dependencies in `mix.exs`: + +```elixir +def deps do + [ + {:util, "~> 0.1.0"} + ] +end +``` + +Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) +and published on [HexDocs](https://hexdocs.pm). Once published, the docs can +be found at [https://hexdocs.pm/util](https://hexdocs.pm/util). + diff --git a/apps/util/lib/thulani/util.ex b/apps/util/lib/thulani/util.ex new file mode 100644 index 0000000..fad5e39 --- /dev/null +++ b/apps/util/lib/thulani/util.ex @@ -0,0 +1,2 @@ +defmodule Thulani.Util do +end diff --git a/apps/util/lib/thulani/util/compose.ex b/apps/util/lib/thulani/util/compose.ex new file mode 100644 index 0000000..cd4435e --- /dev/null +++ b/apps/util/lib/thulani/util/compose.ex @@ -0,0 +1,13 @@ +defmodule Thulani.Util.Compose do + import Thulani.Util.Curry + + def f <|> g, do: compose(f, g) + + def compose(f, g) when is_function(g) do + fn arg -> compose(curry(f), curry(g).(arg)) end + end + + def compose(f, arg) do + f.(arg) + end +end diff --git a/apps/util/lib/thulani/util/curry.ex b/apps/util/lib/thulani/util/curry.ex new file mode 100644 index 0000000..b03afab --- /dev/null +++ b/apps/util/lib/thulani/util/curry.ex @@ -0,0 +1,16 @@ +defmodule Thulani.Util.Curry do + @moduledoc false + + def curry(f) do + {_, arity} = :erlang.fun_info(f, :arity) + curry(f, arity, []) + end + + defp curry(f, 0, args) do + apply(f, Enum.reverse(args)) + end + + defp curry(f, arity, args) do + fn arg -> curry(f, arity - 1, [arg | args]) end + end +end diff --git a/apps/util/mix.exs b/apps/util/mix.exs new file mode 100644 index 0000000..a0caff9 --- /dev/null +++ b/apps/util/mix.exs @@ -0,0 +1,27 @@ +defmodule Thulani.Util.MixProject do + use Mix.Project + + def project do + [ + app: :util, + version: "0.1.0", + build_path: "../../_build", + config_path: "../../config/config.exs", + deps_path: "../../deps", + lockfile: "../../mix.lock", + elixir: "~> 1.9", + start_permanent: Mix.env() == :prod, + deps: deps() + ] + end + + def application do + [ + extra_applications: [:logger] + ] + end + + defp deps do + [] + end +end diff --git a/apps/util/test/test_helper.exs b/apps/util/test/test_helper.exs new file mode 100644 index 0000000..869559e --- /dev/null +++ b/apps/util/test/test_helper.exs @@ -0,0 +1 @@ +ExUnit.start() diff --git a/apps/util/test/thulani/util_test.exs b/apps/util/test/thulani/util_test.exs new file mode 100644 index 0000000..9246f40 --- /dev/null +++ b/apps/util/test/thulani/util_test.exs @@ -0,0 +1,4 @@ +defmodule Thulani.UtilTest do + use ExUnit.Case + doctest Thulani.Util +end |
