Comments (3)
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.
@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.
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)
- Is it possible to have a mix of required and optional rows in Record? HOT 16
- Add `purescript-option` to the package set HOT 4
- Document installation
- Provide a way to get any values that exist in an `Option.Option _` or none at all
- Question on using ToRecord HOT 13
- Proposal: getAll alternative that returns an Either with errors (missing required fields) HOT 4
- Defining setMay HOT 2
- A PR to be PureScript 0.14.x compatible? HOT 4
- Drop support for `purescript-simple-json`
- Documentation for alter function HOT 2
- PureScript 0.15 support HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from purescript-option.