Skip to content
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

basic result type and functions #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tsloughter
Copy link
Member

No description provided.

src/result.alp Outdated
import_type option.option

export_type result

Copy link
Contributor

Choose a reason for hiding this comment

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

export is_ok, map, etc?

@j14159
Copy link
Contributor

j14159 commented Jan 5, 2018

@tsloughter sorry to leave you hanging on this! Aside from some missing exports I think this is awesome. Thanks!

Some x -> Ok x
| None -> Err e

let andThen callback (Ok value) = callback value
Copy link
Contributor

Choose a reason for hiding this comment

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

Here we are using camelCase while everywhere else we are using snake_case. Could we be consistent?

Copy link
Contributor

Choose a reason for hiding this comment

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

Have we decided which case we prefer? I'm leaning towards camelCase.

Copy link
Contributor

Choose a reason for hiding this comment

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

iirc @lepoetemaudit and I discussed this mid-way through last year and settled on moving to camelCase. I'm easy either way tbh. Other opinions?

Copy link
Contributor

Choose a reason for hiding this comment

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

Fab, I'll update the other modules/PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

For option this is called flatMap. Which name do we prefer? I took flatMap from Scala as we had option which felt Scala-y to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

I prefer andThen personally, but would also change it in option, hehe. So if it is staying that way in option then to be consistent I'll change it here.

Maybe in scala the option and result types are actually related to sequences and so a flatMap makes sense? To me it doesn't fit in the alpaca case and would be confusing.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's the result of composing flatten : m m a -> m a and map, so I think it makes sense.

I find the name andThen a little odd, doesn't seem to fit with map, fold etc

src/result.alp Outdated
let of_option opt e =
match opt with
Some x -> Ok x
| None -> Err e
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we can this from_option? That name is more common everywhere but OCaml and I think it is easier to discover as the name is closer to spoken English.

@tsloughter
Copy link
Member Author

no worries, thanks for the comments, I'll look at this over the weekend.

@tsloughter tsloughter force-pushed the result-type branch 2 times, most recently from fe3ccd6 to 3a02c90 Compare January 15, 2018 19:14
@tsloughter
Copy link
Member Author

Updated.

No reason to have rebar.lock in the gitignore, I think it is just confusing to do so? But I can add that back, it conflicted with my adding _checkouts to the ignore so I had to merge them.

@lpil
Copy link
Contributor

lpil commented Jan 15, 2018

The lock isn't used for libraries, right? Is it best practice to gitignore it or not?

@tsloughter
Copy link
Member Author

@lpil it is used. The lock is always used because of the way rebar3 does dependency resolution, http://www.rebar3.org/docs/dependencies , which is the maven model.

@lpil
Copy link
Contributor

lpil commented Jan 15, 2018

Cool, thanks for the link :)

@j14159
Copy link
Contributor

j14159 commented Jan 20, 2018

Ready to merge?

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.

None yet

3 participants