Last active
June 9, 2019 13:33
-
-
Save fczuardi/3967873ecd1f8fc7a56d8f16c5eb7c40 to your computer and use it in GitHub Desktop.
Caipyra Code Snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type product; | |
type payment; | |
type sale; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type product = | |
| AGUA_300ML | |
| GELATO_PEQUENO | |
| GELATO_MEDIO | |
| CAFE_ESPRESSO; | |
type payment; | |
type sale; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type product = | |
| AGUA_300ML | |
| GELATO_PEQUENO | |
| GELATO_MEDIO | |
| CAFE_ESPRESSO; | |
type payment; | |
type sale = { | |
products: list(product), | |
payments: list(payment), | |
}; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type product = | |
| AGUA_300ML | |
| GELATO_PEQUENO | |
| GELATO_MEDIO | |
| CAFE_ESPRESSO; | |
type amount; | |
type provider; | |
type payment = | |
| Cash(amount) | |
| CreditCard(provider, amount); | |
type sale = { | |
products: list(product), | |
payments: list(payment), | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type product = | |
| AGUA_300ML | |
| GELATO_PEQUENO | |
| GELATO_MEDIO | |
| CAFE_ESPRESSO; | |
module Payment = { | |
type amount; | |
type provider; | |
type t = | |
| Cash(amount) | |
| CreditCard(provider, amount); | |
}; | |
type sale = { | |
products: list(product), | |
payments: list(Payment.t), | |
}; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type product = | |
| AGUA_300ML | |
| GELATO_PEQUENO | |
| GELATO_MEDIO | |
| CAFE_ESPRESSO; | |
module Payment = { | |
type amount; | |
type provider; | |
type t = | |
| Cash(amount) | |
| CreditCard(provider, amount); | |
}; | |
type sale = { | |
products: list(product), | |
payments: list(Payment.t), | |
}; | |
/* implementation */ | |
let addProduct = (cart, product) => cart @ [product]; | |
let cart = | |
[] | |
->addProduct(GELATO_MEDIO) | |
->addProduct(AGUA_300ML) | |
->addProduct(CAFE_ESPRESSO); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type product = | |
| AGUA_300ML | |
| GELATO_PEQUENO | |
| GELATO_MEDIO | |
| CAFE_ESPRESSO; | |
module Payment = { | |
type amount; | |
type provider; | |
type t = | |
| Cash(amount) | |
| CreditCard(provider, amount); | |
}; | |
type sale = { | |
products: list(product), | |
payments: list(Payment.t), | |
}; | |
/* implementation */ | |
let getPrice = product => | |
switch (product) { | |
| GELATO_MEDIO => 14.00 | |
| GELATO_PEQUENO => 12.00 | |
| CAFE_ESPRESSO => 6.00 | |
| AGUA_300ML => 4.00 | |
}; | |
let addProduct = (cart, product) => cart @ [product]; | |
let cart = | |
[] | |
->addProduct(GELATO_MEDIO) | |
->addProduct(AGUA_300ML) | |
->addProduct(CAFE_ESPRESSO); | |
Js.log(getPrice(CAFE_ESPRESSO)); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type product = | |
| AGUA_300ML | |
| GELATO_PEQUENO | |
| GELATO_MEDIO | |
| CAFE_ESPRESSO; | |
module Payment = { | |
type amount; | |
type provider; | |
type t = | |
| Cash(amount) | |
| CreditCard(provider, amount); | |
}; | |
type sale = { | |
products: list(product), | |
payments: list(Payment.t), | |
}; | |
/* implementation */ | |
let getPrice = product => | |
switch (product) { | |
| GELATO_MEDIO => 14.00 | |
| GELATO_PEQUENO => 12.00 | |
| CAFE_ESPRESSO => 6.00 | |
| AGUA_300ML => 4.00 | |
}; | |
let addProduct = (cart, product) => cart @ [product]; | |
let cart = | |
[] | |
->addProduct(GELATO_MEDIO) | |
->addProduct(AGUA_300ML) | |
->addProduct(CAFE_ESPRESSO); | |
let sumPrice = (subtotal, product) => getPrice(product) +. subtotal; | |
let evaluateTotal = ListLabels.fold_left(~f=sumPrice, ~init=0.0, _); | |
Js.log(evaluateTotal(cart)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment