Skip to content

Add fromNonEmpty operation #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 13, 2015
Merged

Conversation

garyb
Copy link
Member

@garyb garyb commented Jul 13, 2015

This kinda sucks maybe? Is there a better way of doing this that you can think of?

@paf31
Copy link
Contributor

paf31 commented Jul 13, 2015

I think I'd rather just pass the function in:

foldNonEmpty :: forall f a r. (a -> f a -> r) -> NonEmpty f a -> r

@garyb
Copy link
Member Author

garyb commented Jul 13, 2015

I thought about that, but providing the fold doesn't help too much as NonEmpty's constructor is already exported.

@garyb
Copy link
Member Author

garyb commented Jul 13, 2015

Although... maybe. I guess fromNonEmpty cons nel is slightly than having to do the pattern match, etc.

@garyb
Copy link
Member Author

garyb commented Jul 13, 2015

How about this then? One for the lazy, and one for when you want to do it properly? 😉

@paf31
Copy link
Contributor

paf31 commented Jul 13, 2015

Why not use Alternative and call it oneOf? It seems like it generalizes certain functions on things like parsers.

@garyb
Copy link
Member Author

garyb commented Jul 13, 2015

Uh, because I foolishly forgot Applicative was a superclass of Alternative. I'm not sure oneOf is quite right though, as you're getting at least one back.

@paf31
Copy link
Contributor

paf31 commented Jul 13, 2015

Well it depends how you interpret f I guess. If you pick f as List, do you think f a represents zero or more values a or one value a in a model with multiple worlds? With Parser this view is more obvious - we think of Parser a as one a in a model supporting an ambient text buffer, but we could also think of it as a collection of as indexed by input documents :)

@garyb
Copy link
Member Author

garyb commented Jul 13, 2015

I did see what you were getting at, I just wonder about that naming in the context of NonEmpty?

@paf31
Copy link
Contributor

paf31 commented Jul 13, 2015

someOf? I dunno ... :)

@paf31
Copy link
Contributor

paf31 commented Jul 13, 2015

Actually, I guess all you need is Alt.

@garyb
Copy link
Member Author

garyb commented Jul 13, 2015

How would that work? You need to put a in f, so need pure:

??? (NonEmpty a fa) = pure a <|> fa

@paf31
Copy link
Contributor

paf31 commented Jul 13, 2015

Ah right, I thought Applicative <= Alt, but it's not.

@garyb
Copy link
Member Author

garyb commented Jul 13, 2015

There we go.

paf31 added a commit that referenced this pull request Jul 13, 2015
Add fromNonEmpty operation
@paf31 paf31 merged commit 8a6a506 into purescript:master Jul 13, 2015
@paf31
Copy link
Contributor

paf31 commented Jul 13, 2015

👍 Thanks!

@garyb garyb deleted the from-nonempty branch July 11, 2016 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants