Created
January 11, 2015 17:33
-
-
Save MikeMKH/a6f8c28517f5c00133e5 to your computer and use it in GitHub Desktop.
Very simple example of Mapcat in C# and Clojure
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
(mapcat #(map inc %) [[1 2 3 4] [20 10]]) | |
;; (2 3 4 5 21 11) | |
(map inc | |
(mapcat identity [[1 2 3 4] [20 10]])) | |
;;(2 3 4 5 21 11) | |
(->> | |
[[1 2 3 4] [20 10]] | |
(mapcat identity) | |
(map inc)) | |
;;(2 3 4 5 21 11) |
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
new[] { | |
new[] {1, 2, 3, 4}, | |
new[] {20, 10} | |
}.SelectMany(x => x.Select(a => a + 1)); | |
// { 2, 3, 4, 5, 21, 11 } | |
csharp> new[] { | |
new[] {1, 2, 3, 4}, | |
new[] {20, 10} | |
}.SelectMany(x => x).Select(x => x + 1); | |
//{ 2, 3, 4, 5, 21, 11 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See my blog post which goes with this Gist: http://comp-phil.blogspot.com/2015/01/the-city-of-mapcat.html