Skip to content

Instantly share code, notes, and snippets.

@KittyGiraudel
Last active August 29, 2015 14:20
Show Gist options
  • Save KittyGiraudel/b9465f46031da717cc60 to your computer and use it in GitHub Desktop.
Save KittyGiraudel/b9465f46031da717cc60 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// _________ .___
// \_ ___ \ ____ __| _/____
// / \ \/ / _ \ / __ |/ __ \
// \ \___( <_> ) /_/ \ ___/
// \______ /\____/\____ |\___ >
// \/ \/ \/
/// Apply $function on each item from $list
/// using current item as first argument
/// and $args as optional extra arguments
/// @author Hugo Giraudel
/// @param {List} $list - List to run function on
/// @param {String} $function - Name of function to run
/// @param {Arglist} $args - Optional extra arguments
/// @return {List}
@function map($list, $function, $args...) {
@for $i from 1 through length($list) {
$list: set-nth($list, $i, call($function, nth($list, $i), $args...));
}
@return $list;
}
// ________
// \______ \ ____ _____ ____
// | | \_/ __ \ / \ / _ \
// | ` \ ___/| Y Y ( <_> )
// /_______ /\___ >__|_| /\____/
// \/ \/ \/
@function double($value) {
@return $value * 2;
}
@function multiply($a, $b) {
@return $a * $b;
}
.foo {
$list: (1, 2, 3, 4, 5);
content: map($list, 'double');
content: map($list, 'multiply', 5);
}
.bar {
$list: ('a', 'b', 'c', 'd', 'e');
content: map($list, 'to-upper-case');
content: map($list, 'unquote');
}
.foo {
content: 2, 4, 6, 8, 10;
content: 5, 10, 15, 20, 25;
}
.bar {
content: 'A', 'B', 'C', 'D', 'E';
content: a, b, c, d, e;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment