Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checked algebraic laws, refactoring #37

Merged
merged 2 commits into from
Oct 16, 2023
Merged

Checked algebraic laws, refactoring #37

merged 2 commits into from
Oct 16, 2023

Conversation

sphaso
Copy link
Owner

@sphaso sphaso commented Oct 15, 2023

After a conversation with Tom, I wanted to check that Noether respects basic Functor and Monadic laws. The good news is that it does, the bad news is that Either.bind should ideally be more strict.
For now I decided to go with a warning in the docs instead of a proper error.

After writing the tests, I decided to increase the inter-function dependency in Maybe. I doubt this will cause any issue in existing codebases, therefore I only consider this a "refactoring change" in the semver.

@@ -60,8 +60,7 @@ defmodule Noether.Either do
{:error, "Value not found"}
"""
@spec join(either()) :: either()
def join({:ok, {:ok, a}}), do: {:ok, a}
def join({:ok, {:error, a}}), do: {:error, a}
def join(a = {_, {_, _}}), do: bind(a, & &1)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Haskell, join from Control.Monad is implemented in terms of bind.

@@ -9,10 +9,10 @@ defmodule Noether.Maybe do

## Examples

iex> map(nil, &Kernel.abs/1)
iex> Noether.Maybe.map(nil, &Kernel.abs/1)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The library that we use for Property Testing has a function called map, therefore I need to break the ambiguity.

@@ -35,9 +35,9 @@ defmodule Noether.MixProject do
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:credo, "~> 1.6.4", only: :dev, runtime: false},
{:credo, "~> 1.7", only: :dev, runtime: false},
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a long due version bump

@sphaso sphaso force-pushed the added_tests_refactoring branch 2 times, most recently from ff37bcf to d5d9c36 Compare October 15, 2023 11:01
@sphaso sphaso force-pushed the added_tests_refactoring branch from d5d9c36 to a5af09e Compare October 15, 2023 11:04
lib/noether/maybe.ex Outdated Show resolved Hide resolved
@sphaso sphaso merged commit 8df5fb4 into main Oct 16, 2023
1 check passed
@sphaso sphaso deleted the added_tests_refactoring branch October 16, 2023 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants