~subsetpark/apcl_ex

49cbf6ab01ac1774b1c1a28dc8dd4d931f7baa1b — Zach Smith a month ago
init
7 files changed, 142 insertions(+), 0 deletions(-)

A .formatter.exs
A .gitignore
A README.md
A apcl.ex
A mix.exs
A test/apcl_ex_test.exs
A test/test_helper.exs
A  => .formatter.exs +4 -0
@@ 1,4 @@
# Used by "mix format"
[
  inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

A  => .gitignore +26 -0
@@ 1,26 @@
# 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").
apcl_ex-*.tar

# Temporary files, for example, from tests.
/tmp/

A  => README.md +22 -0
@@ 1,22 @@
# Apcl

A Practical Combinator Library.

## Installation

The package can be installed by adding `apcl_ex` to your list of dependencies
in `mix.exs`:

```elixir
def deps do
  [
    {:apcl_ex, "~> 0.1.0"}
  ]
end
```

Documentation can be generated with
[ExDoc](https://github.com/elixir-lang/ex_doc) and published on
[HexDocs](https://hexdocs.pm). The docs can be found at
<https://hexdocs.pm/apcl_ex>.


A  => apcl.ex +52 -0
@@ 1,52 @@
defmodule Apcl do
  @moduledoc """
  A Practical Combinator Library.
  """

  @doc """
  Returns its argument.
  """
  def identity(x), do: x

  @doc """
  Returns a function which returns `x` no matter what it is passed.
  """
  def constant(x), do: fn _y -> x end

  @doc """
  Performs function composition.
  """
  def compose(f, g), do: fn x -> f.(g.(x)) end

  @doc """
  Returns a function which applies `f` to `xs`.
  """
  def apply(f), do: fn xs -> apply(f, xs) end

  @doc """
  Returns a function which permutes its arguments and applies `f` to them.
  """
  def flip(f), do: fn x, y -> f.(y, x) end

  @doc """
  Given two arguments, returns the left one.
  """
  def left(x, _y), do: x

  @doc """
  Given two arguments, returns the right one.
  """
  def right(_x, y), do: y

  @doc """
  Returns a function that applies `g` and `h` to its arguments, taking the
  resulting values as the arguments to `f`.
  """
  def recombine(f, g, h), do: fn x -> f.(g.(x), h.(x)) end

  @doc """
  Returns a function that applies `g` to each of its arguments, taking the
  resulting values as the arguments to `f`.
  """
  def under(f, g), do: fn x, y -> f.(g.(x), g.(y)) end
end

A  => mix.exs +33 -0
@@ 1,33 @@
defmodule Apcl.MixProject do
  use Mix.Project

  def project do
    [
      app: :apcl,
      version: "0.1.0",
      elixir: "~> 1.16",
      start_permanent: Mix.env() == :prod,
      deps: deps(),
      package: [
        name: "apcl_ex",
        description: "A Practical Combinator Library",
        licenses: ["BSD-3-Clause"],
        links: %{"Sourcehut" => "https://sr.ht/~subsetpark/apcl/"}
      ]
    ]
  end

  # Run "mix help compile.app" to learn about applications.
  def application do
    [
      extra_applications: [:logger]
    ]
  end

  # Run "mix help deps" to learn about dependencies.
  defp deps do
    [
      {:ex_doc, ">= 0.0.0", only: :dev, runtime: false}
    ]
  end
end

A  => test/apcl_ex_test.exs +4 -0
@@ 1,4 @@
defmodule ApclTest do
  use ExUnit.Case
  doctest Apcl
end

A  => test/test_helper.exs +1 -0
@@ 1,1 @@
ExUnit.start()