Functions

Compatibility (Argument Type):
Dart Sass
LibSass
since 3.5.0
Ruby Sass
since 3.5.0

In older versions of LibSass and Ruby Sass, the call() function took a string representing a function’s name. This was changed to take a function value instead in preparation for a new module system where functions are no longer global and so a given name may not always refer to the same function.

Passing a string to call() still works in all implementations, but it’s deprecated and will be disallowed in future versions.

Functions can be values too! You can’t directly write a function as a value, but you can pass a function’s name to the [get-function() function][] to get it as a value. Once you have a function value, you can pass it to the call() function to call it. This is useful for writing higher-order functions that call other functions.

SCSS Syntax

/// Return a copy of $list with all elements for which $condition returns `true`
/// removed.
@function remove-where($list, $condition) {
  $new-list: ();
  $separator: list-separator($list);
  @each $element in $list {
    @if not call($condition, $element) {
      $new-list: append($new-list, $element, $separator: $separator);
    }
  }
  @return $new-list;
}

$fonts: Tahoma, Geneva, "Helvetica Neue", Helvetica, Arial, sans-serif;

content {
  @function contains-helvetica($string) {
    @return str-index($string, "Helvetica");
  }
  font-family: remove-where($fonts, get-function("contains-helvetica"));
}

Sass Syntax

/// Return a copy of $list with all elements for which $condition returns `true`
/// removed.
@function remove-where($list, $condition)
  $new-list: ()
  $separator: list-separator($list)
  @each $element in $list
    @if not call($condition, $element)
      $new-list: append($new-list, $element, $separator: $separator)


  @return $new-list


$fonts: Tahoma, Geneva, "Helvetica Neue", Helvetica, Arial, sans-serif

content
  @function contains-helvetica($string)
    @return str-index($string, "Helvetica")

  font-family: remove-where($fonts, get-function("contains-helvetica"))

CSS Output

content {
  font-family: Tahoma, Geneva, Arial, sans-serif;
}