Created
June 10, 2020 11:31
-
-
Save bultas/11ceaf15cddf14355b8621801359b94d to your computer and use it in GitHub Desktop.
Pattern Match in javascript
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
import { cond, always, T, whereEq } from "ramda"; | |
export const getProductPrice = cond([ | |
[ | |
whereEq({ | |
type: "product1", | |
currency: "czk", | |
}), | |
({ price }) => `${price} Kc`, | |
], | |
[ | |
whereEq({ | |
type: "product1", | |
currency: "usd", | |
}), | |
({ price }) => `$${price}`, | |
], | |
[T, always(null)], | |
]); | |
getProductPrice({ | |
type: "product1", | |
currency: "usd", | |
price: 200 | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment