Created
December 5, 2013 22:57
-
-
Save pdaoust/7815559 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
This file contains 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
// ---- | |
// Sass (v3.3.0.rc.1) | |
// Compass (v0.13.alpha.10) | |
// ---- | |
// 'map', 'transform', 'select', or 'project' function. Iterate over a list, | |
// performing a function on each item, and collecting the new items. Each | |
// function takes an item as a first argument and returns a transformed item. | |
// You can pass additional arguments to the function too, which is a decent poor | |
// man's function composition. | |
// (I didn't call this f-map because the term 'map' is already used in Sass to | |
// denote a hash or dictionary.) | |
@function f-apply($func, $list, $args...) { | |
$new-list: (); | |
@each $item in $list { | |
$new-list: append($new-list, call($func, $item, $args...)); | |
} | |
@return $new-list; | |
} | |
@function square($x) { | |
@return $x * $x; | |
} | |
p { | |
// using the plain ol' square function | |
square: square(3); | |
// now let's lift it to work on lists using a higher-order function | |
squares: f-apply(square, (1 2 3 4 5 6 7)); | |
} |
This file contains 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
p { | |
square: 9; | |
squares: 1 4 9 16 25 36 49; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment