Giter Club home page Giter Club logo

Comments (4)

KittyGiraudel avatar KittyGiraudel commented on May 29, 2024

You might want to have a look at this: http://sassmeister.com/gist/c36be3440dc2b5ae9ba2.

from sassylists.

thertweck avatar thertweck commented on May 29, 2024

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!

from sassylists.

KittyGiraudel avatar KittyGiraudel commented on May 29, 2024

I'll have a closer look at this.

from sassylists.

KittyGiraudel avatar KittyGiraudel commented on May 29, 2024

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);
}

from sassylists.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.