Skip to content

Instantly share code, notes, and snippets.

@cahnory
Created May 6, 2015 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cahnory/6e6b670a6b6ed1f84197 to your computer and use it in GitHub Desktop.
Save cahnory/6e6b670a6b6ed1f84197 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.4.13)
// Compass (v1.0.3)
// ----
// ----
// 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: ();
@if 'map' == type-of($list) {
@each $key, $item in $list {
@if call($function, $item, $args...) {
$u-list: map-merge($u-list, ($key: $item));
}
}
}
@else {
@each $item in $list {
@if call($function, $item, $args...) {
$u-list: append($u-list, $item, list-separator($list));
}
}
}
@return $u-list;
}
// ________
// \______ \ ____ _____ ____
// | | \_/ __ \ / \ / _ \
// | ` \ ___/| Y Y ( <_> )
// /_______ /\___ >__|_| /\____/
// \/ \/ \/
@function is-even($value) {
@return $value % 2 == 0;
}
.list {
$list: (1, 2, 3, 4, 5);
coma: filter($list, 'is-even');
$list: (1 2 3 4 5);
space: filter($list, 'is-even');
}
.map {
$list: (
a: 1,
b: 2,
c: 3,
d: 4,
e: 5
);
keys: map-keys(filter($list, 'is-even'));
values: map-values(filter($list, 'is-even'));
}
.list {
coma: 2, 4;
space: 2 4;
}
.map {
keys: b, d;
values: 2, 4;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment