-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support reduction #48
Comments
You might want to have a look at this: http://sassmeister.com/gist/c36be3440dc2b5ae9ba2. |
I think it's not quite the same. The walk()-function resembles the typical "map" collection processing pattern. The difference to reduce() would be that the items in a list are reduced to a single value. Applications include calculating the sum/product/... of elements or if the items are strings concat them. For a complete set of lambda style collection processing functions a filter() method could also come in handy sometimes. Btw.: I love your Blog! |
I'll have a closer look at this. |
I would probably implement it like this: @function reduce($list, $function, $base, $args...) {
@if not function-exists($function) {
@error "Cannot find callback `#{$callback}`.";
}
@each $item in $list {
$base: call($function, $base, $item, $args...);
}
@return $base;
}
@function add($a, $b, $args...) {
$result: $a + $b;
@if length($args) == 0 {
@return $result;
}
@each $arg in $args {
$result: $result + $arg;
}
@return $result;
}
test {
a: reduce(a b c d e, add, "");
b: reduce(1 2 3 4 5, add, 0);
c: reduce(red green blue, mix, red);
} |
Hello!
A sl-reduce() function would be great! Check this:
And a callback:
Could be used like this:
The text was updated successfully, but these errors were encountered: