Created
November 16, 2018 14:12
-
-
Save mficzel/e5a2b54fdb49e79b03df75646dc23f20 to your computer and use it in GitHub Desktop.
Examples for Neos.Fusion:Reduce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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