Skip to content

Instantly share code, notes, and snippets.

@KittyGiraudel
Created May 6, 2015 10:24
Show Gist options
  • Save KittyGiraudel/f2a9a0d4365d309a0be9 to your computer and use it in GitHub Desktop.
Save KittyGiraudel/f2a9a0d4365d309a0be9 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.4.13)
// Compass (v1.0.3)
// ----
// _________ .___
// \_ ___ \ ____ __| _/____
// / \ \/ / _ \ / __ |/ __ \
// \ \___( <_> ) /_/ \ ___/
// \______ /\____/\____ |\___ >
// \/ \/ \/
/// Filter $list only keeping item for which $function call
/// with $args as optional extra arguments returns a truthy value.
/// @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 filter($list, $function, $args...) {
$u-list: ();
@each $item in $list {
@if call($function, $item, $args...) {
$u-list: append($u-list, $item);
}
}
@return $u-list;
}
// ________
// \______ \ ____ _____ ____
// | | \_/ __ \ / \ / _ \
// | ` \ ___/| Y Y ( <_> )
// /_______ /\___ >__|_| /\____/
// \/ \/ \/
@function is-even($value) {
@return $value % 2 == 0;
}
.foo {
$list: (1, 2, 3, 4, 5);
content: filter($list, 'is-even');
}
.foo {
content: 2 4;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment