Created
December 1, 2010 14:24
-
-
Save mneedham/723543 to your computer and use it in GitHub Desktop.
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
| # This is how it looks | |
| def calc_price(foo) | |
| price = nil | |
| ["list1", "list2"].each do |list| | |
| price_lists = lookup_price_lists # more logic but irrelevant for example | |
| price = get_price_for(price_lists, foo) | |
| return adjust_price(foo, price) unless price.nil? | |
| end | |
| price | |
| end | |
| Right now the code will look for a price in 'list1' or 'list2' and then exit as soon as it finds | |
| a price. | |
| I think there should be away to write that in a more 'functional' way. Right now I'd say it's quite | |
| imperative. | |
| One way is to 'map' 'lookup_price_lists' on the collection but I don't want that to be done if the | |
| method would have already exited in the previous implementation. | |
| i.e. it shouldn't lookup prices for 'list2' if we've already got a price for 'list1' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment