This file contains 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
// 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 - ' + |
This file contains 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
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" | |
| _ => |
This file contains 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 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!" |
This file contains 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
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!'; | |
}; | |
} |
This file contains 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
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)); |
This file contains 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
let data = [1, 3, 5, 2, 0, 4]; | |
let betterData = data | |
.filter(a => a !== 0) | |
.map(a => a * 2) | |
.map(a => a.toString()); |
This file contains 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
let pow = a => a *. a; | |
let result = "2.5" |> float_of_string |> pow; |
This file contains 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
let pow = a => a * a; | |
let result = pow(parseFloat('2.5')) |
This file contains 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 review = Bad(string) | Neutral | Awesome; | |
let handleOptionChange = review => { | |
/* saving the review somewhere */ | |
} | |
handleOptionChange(Bad("I hate ReasonML")); |
This file contains 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
let handleOptionChange = (option, explanation) => { | |
// saving the option somewhere | |
if (option === "bad" && explanation) { | |
// saving explanation somewhere | |
} | |
} | |
// later in the code | |
handleOptionChange('bad', 'I hate ReasonML'); |
NewerOlder