Created
May 6, 2015 12:20
-
-
Save cahnory/6e6b670a6b6ed1f84197 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
This file contains hidden or 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.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')); | |
} |
This file contains hidden or 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
.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