-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add 'Burger Discounts' chapter #34
Conversation
b94cd54
to
d2967b1
Compare
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 found some outdated paths and a typo, but otherwise all are minor comments. Amazing work! 💪
> Given an order comprising multiple items, find the price of the second most | ||
> expensive burger. Subtract this number from the pre-tax total of the order. |
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.
Wouldn't it be something like this? To make it more generic:
> Given an order comprising multiple items, find the price of the second most | |
> expensive burger. Subtract this number from the pre-tax total of the order. | |
> Given an order comprising multiple items, for every two burgers ordered find the | |
> price of the less expensive one. Subtract this number from the pre-tax total of the | |
> order. |
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.
This makes more sense, but I would like to implement it in the next chapter
docs/burger-discounts/index.md
Outdated
As an extra precaution, you might want to catch the exception inside the switch | ||
expression: | ||
|
||
<<< Discount.re#catch-exception{5} | ||
|
||
With the current logic, it's not impossible to reach the exception branch, but | ||
who knows how the code might evolve in the future. |
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.
Maybe this could be shared as an alternative approach? Rather than "as an extra precaution", something like "as an alternative approach", and then share the code with exn handling and without the .length
check.
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.
Agree, catching the exception is described as alternate approach in 4184366
docs/burger-discounts/index.md
Outdated
It looks like `burger[0]` is using an array access operator, but it's actually | ||
just a function call. That is, `burger[0]` is completely equivalent to | ||
`Array.get(burger, 0)`. |
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 looks like `burger[0]` is using an array access operator, but it's actually | |
just a function call. That is, `burger[0]` is completely equivalent to | |
`Array.get(burger, 0)`. | |
In OCaml, array access operators like `burger[0]` are actually just a | |
function call. That is, `burger[0]` is completely equivalent to | |
`Array.get(burger, 0)`. |
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.
Reworded in 20a777b
functions. In those cases, you can give the compiler more information:
Stdlib
module is opened by defaultfor some fields
value is
()
), so you can useStdlib.ignore
to explicitly discard returnvalues
None
->undefined
Some(value)
->value
array[index]
is actually just a call toArray.get(array, index)
Array
module to override the behavior ofArray.get