Skip to content

Instantly share code, notes, and snippets.

@mficzel
Created November 16, 2018 14:12
Show Gist options
  • Save mficzel/e5a2b54fdb49e79b03df75646dc23f20 to your computer and use it in GitHub Desktop.
Save mficzel/e5a2b54fdb49e79b03df75646dc23f20 to your computer and use it in GitHub Desktop.
Examples for Neos.Fusion:Reduce
sum = Neos.Fusion:Reduce {
items = ${ __array_of_products__ }
initialValue = 0
itemReducer = ${carry + item.price}
}
cheapest = Neos.Fusion:Reduce {
items = ${ __array_of_products__ }
initialValue = null
itemReducer = ${(!carry || carry.price > item.price) ? item : carry}
}
filtered = Neos.Fusion:Reduce {
items = ${ __array_of_products__ }
initialValue = ${[]}
itemReducer = ${(item.price > 99) ? Array.push(carry, item) : carry}
}
#
# This requires new Array.set methods
#
grouped = Neos.Fusion:Reduce {
items = ${ __array_of_products__ }
initialValue = ${[]}
itemReducer = News.Fusion:Value {
groupName = ${item.group}
groupCarry = ${carry[ this.groupName ] || []}
groupValue = ${Array.push(this.groupCarry, item)}
value = ${ Array.set(carry, this.groupName, this.groupValue) }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment