Skip to content

Instantly share code, notes, and snippets.

View souhe's full-sized avatar

Jakub Kłobus souhe

View GitHub Profile
// Autogenerated code by bucklescript after few improvements
function func(userWithReview) {
let { name, phone, review, age } = userWithReview;
if (name === 'Maja') {
if (phone === '123123') {
if (typeof match === 'number') {
if (review !== 0) {
return (
'Here we match every value with name Maja and we can use phone like a normal variable - ' +
switch (userWithReview) {
| { name: "Maja", phone: "123123", review: Neutral, age: 24 } =>
"Here we match every value with name Maja, phone 123123 Neutral review and age 24"
| { name: "Maja", phone } =>
"Here we match every value with name Maja and we can use phone like a normal variable - " ++ phone
| { name, phone, review: Awesome} =>
"Here we match every user with review Awesome and we can use phone and name"
| { name, phone, review: Bad(explanation)} =>
"Here we match every user with review Baw and we can use phone, name, and the explanation"
| _ =>
type review =
| Bad(string)
| Neutral
| Awesome;
let getAnswer = review =>
switch (review) {
| Bad(comment) => "That is sad that you think: " ++ comment
| Neutral => "Okay"
| Awesome => "Yes yes yes!"
let getAnswer = (review, message) => {
switch(review) {
case 'Bad':
return 'That is sad that you think: ' + message;
case 'Neutral':
return 'Okay';
case 'Awesome':
return 'Yes yes yes!';
};
}
let data = [1, 3, 5, 2, 0, 4 ];
data
|> List.filter(i => i != 0)
|> List.map(i => i * 2)
|> List.map(i => string_of_int(i));
let data = [1, 3, 5, 2, 0, 4];
let betterData = data
.filter(a => a !== 0)
.map(a => a * 2)
.map(a => a.toString());
let pow = a => a *. a;
let result = "2.5" |> float_of_string |> pow;
let pow = a => a * a;
let result = pow(parseFloat('2.5'))
type review = Bad(string) | Neutral | Awesome;
let handleOptionChange = review => {
/* saving the review somewhere */
}
handleOptionChange(Bad("I hate ReasonML"));
let handleOptionChange = (option, explanation) => {
// saving the option somewhere
if (option === "bad" && explanation) {
// saving explanation somewhere
}
}
// later in the code
handleOptionChange('bad', 'I hate ReasonML');