liveBook · Manning

Item operation

As explained in Grokking Simplicity

A computation that operates on an item while depending on the item's structural representation.

An item operation computes on an item while depending on the item's structural representation. In shopping-cart code, that means knowing the fields or shape of an item, such as its name and price. section 5.11 section 6.1

Common item operations include:

Reading a cart item

In calc_total(cart), the calculation accesses item.price while traversing the cart. That access gives the function item knowledge; the total calculation may also carry business meaning, so categories can overlap. section 5.6


C  I function add_item(cart, name, price) {     var new_cart = cart.slice(); #1     new_cart.push({         name: name,         price: price     });     return new_cart; }
C  I  B function calc_total(cart) { #2     var total = 0;     for(var i = 0; i < cart.length; i++) {         var item = cart[i];         total += item.price;     }    return total; }
B function gets_free_shipping(cart) {     return calc_total(cart) >= 20; }
B function calc_tax(amount) {     return amount * 0.10; }

Inspect the classification marks on add_item, calc_total, gets_free_shipping, and calc_tax to see how item structure relates to cart operations and business rules. section 5.6

How Grokking Simplicity covers it

How deep it goes
Defines the category and lists operations, while deferring deeper separation into distinct code layers.
Examples
Uses shopping-cart items, item names and prices, calc_total, add_item, and operations for getting or setting item values.
What you can do after
Evaluate calculations by the data structures they know and recognize where item knowledge overlaps with business rules.
How it connects
Connects item operations with cart operations, business rules, array utilities, immutability, and nested data.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Simplicity. The section links point to the parts of the book it draws on.