Skip to content

Instantly share code, notes, and snippets.

@MikeMKH
Created January 11, 2015 17:33
Show Gist options
  • Save MikeMKH/a6f8c28517f5c00133e5 to your computer and use it in GitHub Desktop.
Save MikeMKH/a6f8c28517f5c00133e5 to your computer and use it in GitHub Desktop.
Very simple example of Mapcat in C# and Clojure
(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)
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 }
@MikeMKH
Copy link
Author

MikeMKH commented Jan 11, 2015

See my blog post which goes with this Gist: http://comp-phil.blogspot.com/2015/01/the-city-of-mapcat.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment