Skip to content

Conversation

@dkoontz
Copy link

@dkoontz dkoontz commented Sep 21, 2016

I was trying to construct a prism for Nullable JS data and exposing notNull seemed the most straightforward way to get the right type. This also give future users a prism to use.


import Data.Lens (prism')
import Data.Nullable (Nullable, notNull, toMaybe)
import Data.Profunctor.Choice (class Choice)
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't this need to go into bower.json?

import Data.Profunctor.Choice (class Choice)

_NotNull :: forall p a. (Choice p) => p a a -> p (Nullable a) (Nullable a)
_NotNull = prism' notNull toMaybe
Copy link
Contributor

Choose a reason for hiding this comment

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

What about making this an Iso between Nullable and Maybe. Then you can reuse _Just, and you don't need to export notNull, which I think has a slightly confusing name.

@dkoontz
Copy link
Author

dkoontz commented Sep 21, 2016

Quite right about the bower dependency. I've never used Iso so I'll look into that.

@paf31
Copy link
Contributor

paf31 commented Dec 28, 2016

Bump

@dkoontz
Copy link
Author

dkoontz commented Jan 25, 2017

Is this the kind of thing you were thinking? The Prism can be defined separately in terms of isoNullableMaybe or were you saying to do this and also add the Prism?

@paf31
Copy link
Contributor

paf31 commented Jan 25, 2017

@dkoontz Sorry, no, I was referring to this Iso, the one from profunctor-lenses. That way, it would be compatible with other types of optics.

@dkoontz
Copy link
Author

dkoontz commented Jan 30, 2017

Sorry I'm not following, if notNull is not exported how would I create the Iso in a separate module? Do you want the Iso declaration in Data.Nullable

@paf31
Copy link
Contributor

paf31 commented Jan 30, 2017

Do you want the Iso declaration in Data.Nullable

Yes please. Something like

import Data.Profunctor

isoToMaybe :: forall p a b. Profunctor p => p (Nullable a) (Nullable b) -> p (Maybe a) (Maybe b)
isoToMaybe = dimap toNullable toMaybe 

By using profunctors, we don't need to add the dependency on profunctor-lenses.

@paf31
Copy link
Contributor

paf31 commented Jun 3, 2017

Since this is now a bit different from the proposal, I'll close it and make an issue instead. Thanks anyway!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants