Giter Site home page Giter Site logo

Comments (3)

joneshf avatar joneshf commented on July 21, 2024

Sorry, I totally missed this. Is this still relevant, or have you figured a way out here? Happy to have the discussion, but don't want to if you're already good.

from purescript-option.

bbarker avatar bbarker commented on July 21, 2024

@joneshf I think it is still relevant, but not urgent in the sense I have a workaround. But the two proposed functions (project and getSubset) seem generally useful. However, the way I've implemented them may not be ideal.

from purescript-option.

joneshf avatar joneshf commented on July 21, 2024

Gotcha.

I'm not really sure what you're wanting to do with these two values. Is there a brief example of how you might use these? Based on the names, I'm making the assumption that you've got a big option and you want a smaller one. Is that about right?

Forgive me if you've already figured this out, but I also wonder if this is something that can be solved with row-polymorphism? Sometimes with these problems, if we open the row on a value (not on the type, necessarily), it can solve these problems. Sometimes inference messes up, so it's not a panacea.

For example, if we've got this:

type Person
  = Option
      ( firstName :: String
      , lastName :: String
      )

displayName ::
  Person ->
  String
displayName person = case firstName person, lastName person of
  Just first, Just last -> first <> " " <> last
  Just first, Nothing -> first
  Nothing, Just last -> last
  Nothing, Nothing -> "Anonymous"

firstName ::
  Person ->
  Data.Maybe.Maybe String
firstName person = Option.get (Data.Symbol.SProxy :: _ "firstName") person

lastName ::
  Person ->
  Data.Maybe.Maybe String
lastName person = Option.get (Data.Symbol.SProxy :: _ "lastName") person

But we don't want firstName and lastName to know about the whole person, we can change them to something like:

firstName ::
  forall option.
  Option
    ( firstName :: String
    | option
    ) ->
  Data.Maybe.Maybe String
firstName person = Option.get (Data.Symbol.SProxy :: _ "firstName") person

lastName ::
  forall option.
  Option
    ( lastName :: String
    | option
    ) ->
  Data.Maybe.Maybe String
lastName person = Option.get (Data.Symbol.SProxy :: _ "lastName") person

from purescript-option.

Related Issues (12)

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.