Skip to content

Support reduction #48

@thertweck

Description

@thertweck

Hello!

A sl-reduce() function would be great! Check this:

@function reduce($list, $callback, $accumulator: 0){
    @if(not function-exists($callback)){
        @warn "Cannot find callback '" + inspect($callback) + "'.";
        @return $accumulator;
    }@else{
        @each $item in $list {
            $accumulator: call($callback, $accumulator, $item);
        }
        @return $accumulator;
    }
}

And a callback:

@function add($a, $b){
    @return $a + $b;
}

Could be used like this:

@debug reduce((1 2 3), add); // yields 6
@debug reduce(("hello" "world"), add, ""); // yields "hello world"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions