-
Notifications
You must be signed in to change notification settings - Fork 5
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
base: master
Are you sure you want to change the base?
Conversation
1d8395b
to
5248e70
Compare
src/result.alp
Outdated
import_type option.option | ||
|
||
export_type result | ||
|
There was a problem hiding this comment.
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?
@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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
no worries, thanks for the comments, I'll look at this over the weekend. |
fe3ccd6
to
3a02c90
Compare
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. |
3a02c90
to
bc692c8
Compare
The lock isn't used for libraries, right? Is it best practice to gitignore it or not? |
@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. |
Cool, thanks for the link :) |
Ready to merge? |
No description provided.