Skip to content

Commit

Permalink
Remove zip_with, version 1 (#39)
Browse files Browse the repository at this point in the history
Co-authored-by: sphaso <sphaso@users.noreply.github.com>
  • Loading branch information
sphaso and sphaso authored Oct 24, 2024
1 parent 62916b7 commit 23a1f48
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 36 deletions.
18 changes: 1 addition & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The root module has a few simple functions one might find of use.
```elixir
def deps do
[
{:noether, "~> 0.3.0"}
{:noether, "~> 1.0.0"}
]
end
```
Expand Down Expand Up @@ -84,22 +84,6 @@ alias Noether.List

Easier to read, less verbose, and it encapsulates the handling of `{:ok, _}` tuples. You can focus on writing actual logic instead of repeating the same pattern matches every time.

After looking at `Maybe` and `Either`, let's take a look at `List`. Suppose you have two lists of numbers you want to sum in order, just like this:

```elixir
[1, 2, 3]
|> Enum.zip([4, 5, 6])
|> Enum.map(fn {a, b} -> a + b end)
```

Noether has a built-in `zip_with` function coming to the rescue:

```elixir
alias Noether.List, as: NList

NList.zip_with([1, 2, 3], [4, 5, 6], &(&1 + &2))
```

## Contributing

Feel free to propose any function you deem useful and even vaguely related to the ones currently present.
Expand Down
18 changes: 0 additions & 18 deletions lib/noether/list.ex
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
defmodule Noether.List do
@moduledoc nil

import Noether
alias Noether.Either

@type fun1 :: (any() -> any())
@type fun2 :: (any(), any() -> any())

@doc """
Given two lists and a function of arity 2, the lists are first zipped and then each tuple is applied (curried) to the function.
## Examples
iex> zip_with([1, 2, 3], [4, 5, 6], &Kernel.+/2)
[5, 7, 9]
"""
@deprecated "use Enum.zip_with/3 instead"
@spec zip_with([any()], [any()], fun2()) :: [any()]
def zip_with(a, b, f) when is_function(f, 2) do
a
|> Enum.zip(b)
|> Enum.map(&curry(&1, f))
end

@doc """
Given a predicate, a function of arity 1, and a value, the function is applied repeatedly until the predicate applied to the value returns either `nil`, `false`, or `{:error, _}`. The list of results is returned.
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Noether.MixProject do
def project do
[
app: :noether,
version: "0.3.0",
version: "1.0.0",
elixir: "~> 1.13",
start_permanent: Mix.env() == :prod,
aliases: aliases(),
Expand Down

0 comments on commit 23a1f48

Please sign in to comment.