Node.js 一个 Elm 语言的代码例子

chenge · 2016年12月31日 · 6963 次阅读

这是一个购物车的例子,大家感受评论下。

来自原文

import List exposing (..) 

cart = []

item product quantity = { product = product, qty = quantity }

product name price = { name = name, price = price }

add cart product = 
  if isEmpty (filter (\item -> item.product == product) cart) 
    then append cart [item product 1] 
    else cart 

subtotal cart = -- we want to calculate cart subtotal 
  sum (map (\item -> item.product.price * toFloat item.qty) cart)
暂无回复。
需要 登录 后方可回复, 如果你还没有账号请 注册新账号