Skip to content

Instantly share code, notes, and snippets.

@bultas
Created June 10, 2020 11:31
Show Gist options
  • Save bultas/11ceaf15cddf14355b8621801359b94d to your computer and use it in GitHub Desktop.
Save bultas/11ceaf15cddf14355b8621801359b94d to your computer and use it in GitHub Desktop.
Pattern Match in javascript
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