Git Product home page Git Product logo

noether's People

Contributors

c0m3tx avatar cottinisimone avatar kmos avatar neslinesli93 avatar ogratton avatar paolosimone avatar sphaso avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

noether's Issues

unwrap with fun or unwrap_or_else

I was wondering if could be useful to modify the unwrap function in order to accept a function as second param (matching).
The implementation:

@spec unwrap(any()) :: any()
def unwrap(a, b \\ nil)
def unwrap({:ok, a}, _), do: a
def unwrap({:error, error}, or_else) when is_function(or_else, 1), do: or_else.(error)
def unwrap(_, default), do: default

Otherwise what about something like the rust unwrap_or_else function in Result?

In my mind could be very useful when you want to get the either :ok value or raise the :error. Or maybe when you need to transform the error into something else.

What do you think?

Thank you, Simone

Add map_all method

Please add a method called map_all.

Given a list of values and a function (any -> {:ok, any} | {:error, any}) should return {:ok [any]} with mapped values if every mapped value result in {:ok, any}. {:error, any} otherwise (maybe the first error returned by function)

Implement some kind of "first matching" function in Either

Big picture:
having a function that applies another function on each element until it results in an {:ok, a} and stops at that point.

Example:
find the first format that matches a particular date. The "first matching" function iterates over the list of formats, applies Timex.parse and returns the first result matching an :ok pattern

Naive-ish implementation using the existing choose:

def first_matching(list, f) do
  Enum.reduce(list, {:error, nil}, fn el, acc ->
     Either.map(acc, fn _ -> Either.choose(el, f, & &1) end)
  end)
end

Implement flat_map

either module could have a flat_map and flatten to flat nested oks (right value mapped)

Moreover could be useful to implement a map_ok and map_error functions

Fix the docs

The examples are all formatted poorly. There's some typos and a link to the Elixir List on the main page.

Try.* functions

PR #29 highlighted how there's a set of functions from Scala\Haskell that we haven't considered. In particular Try.map from Scala acts as a functor on Try objects, applying a function in case no exception was thrown.
Currently we have Either.try which maps a function application to an either, i.e., :ok if the function succeeded, :error if an exception was thrown.

A few questions from the top of my head:

  • do we need Try.map when the user could use the with construct? (or just map after the Either.try)
  • are there other functions outside of Either.try that we could implement?
  • would it make sense to treat Try as a separate module (i.e. not piggybacking on either)?

@paolosimone @neslinesli93 @cottinisimone

Rethinking API

The current set of functions is a mix between Haskell and Scala. I'd like to keep it more consistent with Haskell.

Two examples:
Either.flat_map is really Either.join

Either.map_error doesn't make much sense, since you end up with stuff like:

   |> Either.map(&Map.get(&1, :create, %{}))
   |> Either.map_error(fn reason -> ... end)

but in Haskell there's just an either function that takes two functions, one for each branch.

Is there anything else?

Release 0.2.2

  • add three new collaborators to the mix.exs file
  • remember to bump version in the README
  • update CHANGELOG
  • relese to hex

Add CI

CircleCI or Travis?

Let's add a vanity badge to see if the build is green on master :P

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.