Coder Social home page Coder Social logo

Comments (4)

fuadsaud avatar fuadsaud commented on August 28, 2024

Does it make sense to have a "general" implementation of to_maybe for Either? I see haskell implements leftToMaybe and rightToMaybe, which behave a little differently:

http://hackage.haskell.org/package/either-4.3.3.2/docs/Data-Either-Combinators.html#v:leftToMaybe

from dry-monads.

flash-gordon avatar flash-gordon commented on August 28, 2024

Either#to_maybe is equivalent (with minor nil exception) to rightToMaybe. We don't have an analog of leftToMaybe because this means adding one more method to Either class and we want to keep it concise. We could add a module with combinators for this implemented as class-level methods

class Either
  module Combinators
    def self.left_to_maybe(either)
      # ...
    end
  end
  C = Combinators
end

Either.C.left_to_maybe

Rather verbose, but afraid it's best we can have in ruby

from dry-monads.

fuadsaud avatar fuadsaud commented on August 28, 2024

@flash-gordon interesting. That could be implemented with refinements as well, in order to keep it more ruby-ish (even though a separate module would keep things even simpler and I like simple), but I definitely understand your point. I'm gonna get a pr to fix this issue since #26 looks stale.

from dry-monads.

flash-gordon avatar flash-gordon commented on August 28, 2024

OK, this fixed in master

from dry-monads.

Related Issues (20)

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.