2018-09-01 22:35:20 +02:00
|
|
|
---
|
|
|
|
title: Functions
|
|
|
|
---
|
|
|
|
|
|
|
|
<% impl_status dart: true, libsass: '3.5.0', ruby: '3.5.0' do %>
|
2018-10-23 22:42:40 +02:00
|
|
|
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.
|
2018-09-01 22:35:20 +02:00
|
|
|
|
2018-10-23 22:42:40 +02:00
|
|
|
[`call()` function]: ../functions/meta#call
|
2018-09-01 22:35:20 +02:00
|
|
|
<% end %>
|
|
|
|
|
|
|
|
[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.
|
|
|
|
|
|
|
|
[Functions]: ../at-rules/function
|
|
|
|
[`get-function` function]: ../functions/meta#get-function
|
|
|
|
[`call()` function]: ../functions/meta#call
|
|
|
|
|
|
|
|
<%# TODO(nweiz): auto-generate this CSS once we're compiling with Dart Sass %>
|
|
|
|
|
|
|
|
<% example do %>
|
2018-10-23 22:42:40 +02:00
|
|
|
/// 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);
|
|
|
|
}
|
2018-09-01 22:35:20 +02:00
|
|
|
}
|
2018-10-23 22:42:40 +02:00
|
|
|
@return $new-list;
|
2018-09-01 22:35:20 +02:00
|
|
|
}
|
|
|
|
|
2018-10-23 22:42:40 +02:00
|
|
|
$fonts: Tahoma, Geneva, "Helvetica Neue", Helvetica, Arial, sans-serif;
|
2018-09-01 22:35:20 +02:00
|
|
|
|
2018-10-23 22:42:40 +02:00
|
|
|
content {
|
|
|
|
@function contains-helvetica($string) {
|
|
|
|
@return str-index($string, "Helvetica");
|
|
|
|
}
|
|
|
|
font-family: remove-where($fonts, get-function("contains-helvetica"));
|
2018-09-01 22:35:20 +02:00
|
|
|
}
|
2018-10-23 22:42:40 +02:00
|
|
|
===
|
|
|
|
/// 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)
|
2018-09-01 22:35:20 +02:00
|
|
|
|
|
|
|
|
2018-10-23 22:42:40 +02:00
|
|
|
@return $new-list
|
2018-09-01 22:35:20 +02:00
|
|
|
|
|
|
|
|
2018-10-23 22:42:40 +02:00
|
|
|
$fonts: Tahoma, Geneva, "Helvetica Neue", Helvetica, Arial, sans-serif
|
2018-09-01 22:35:20 +02:00
|
|
|
|
2018-10-23 22:42:40 +02:00
|
|
|
content
|
|
|
|
@function contains-helvetica($string)
|
|
|
|
@return str-index($string, "Helvetica")
|
2018-09-01 22:35:20 +02:00
|
|
|
|
2018-10-23 22:42:40 +02:00
|
|
|
font-family: remove-where($fonts, get-function("contains-helvetica"))
|
|
|
|
===
|
|
|
|
content {
|
|
|
|
font-family: Tahoma, Geneva, Arial, sans-serif;
|
|
|
|
}
|
2018-09-01 22:35:20 +02:00
|
|
|
<% end %>
|