Systematic Architecture [EN]
The blog on systems development/architecture, to be a beautiful, artistic one.
Friday, 31 July 2015
Functional Patterns - zip
How to manipulate each pair of two collections. zip === Let's say two lists you have and you want to add each pair of them, like ``` 1 + 6 2 + 7 3 + 8 4 + 9 5 + 10 ``` Going on with Scala ```scala List a 1 2 3 4 5 ``` ```scala List b 6 7 8 9 10 ``` ```scala val c = a zip b ``` ```scala List c (1, 6) (2, 7) (3, 8) (4, 9) (5, 10) ``` ```scala val results = c map {case (a, b) => {a + b}} ```
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment