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

chenge · December 31, 2016 · 6963 hits

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

来自原文

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)
No Reply at the moment.
You need to Sign in before reply, if you don't have an account, please Sign up first.