Created
September 18, 2012 03:34
-
-
Save briantrice/3741095 to your computer and use it in GitHub Desktop.
A stupid-simple cross-product for collections
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
collections define: #CrossProduct &slots: {#rows -> #{}. #columns -> #{}}. | |
c@(Collection traits) <*> d@(Collection traits) | |
[ | |
CrossProduct new `>> [rows := c. columns := d. ] | |
]. | |
cross@(CrossProduct traits) do: block | |
[ | |
c do: [| :a | | |
d do: [| :b | | |
block apply*, a, b]] | |
]. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment