Skip to content

Instantly share code, notes, and snippets.

View pdaoust's full-sized avatar

Paul d'Aoust pdaoust

View GitHub Profile
@pdaoust
pdaoust / SassMeister-input.scss
Created December 6, 2013 21:58
Generated by SassMeister.com.
// ----
// Sass (v3.3.0.rc.1)
// Compass (v0.13.alpha.10)
// ----
@function square($x) {
$squared: $x * $x;
@return $squared;
}
@pdaoust
pdaoust / SassMeister-input.scss
Created December 6, 2013 21:56
Generated by SassMeister.com.
// ----
// Sass (v3.3.0.rc.1)
// Compass (v0.13.alpha.10)
// ----
p {
$color: red;
color: $color;
}
/* #{$color} */
@pdaoust
pdaoust / SassMeister-input.scss
Created December 6, 2013 21:55
Generated by SassMeister.com.
// ----
// Sass (v3.3.0.rc.1)
// Compass (v0.13.alpha.10)
// ----
$names: Jim Sandy Clem;
@each $name in $names {
/* Hi, I am #{$name}. */
$most-recent-name: $name;
}
@pdaoust
pdaoust / SassMeister-input.scss
Created December 5, 2013 23:33
Generated by SassMeister.com.
// ----
// Sass (v3.3.0.rc.1)
// Compass (v0.13.alpha.10)
// ----
@function f-fold($func, $list, $initial, $args...) {
$start: 1;
@if $initial == null {
// If there's no initial value, use the first in the list.
$start: 2;
@pdaoust
pdaoust / SassMeister-input.scss
Created December 5, 2013 23:17
Generated by SassMeister.com.
// ----
// Sass (v3.3.0.rc.1)
// Compass (v0.13.alpha.10)
// ----
@function f-fold($func, $prev, $list, $args...) {
@each $item in $list {
$prev: call($func, $prev, $item, $args...);
}
@return $prev;
@pdaoust
pdaoust / SassMeister-input.scss
Created December 5, 2013 23:14
Generated by SassMeister.com.
// ----
// Sass (v3.3.0.rc.1)
// Compass (v0.13.alpha.10)
// ----
@function f-apply($func, $list, $args...) {
$new-list: ();
@each $item in $list {
$new-list: append($new-list, call($func, $item, $args...));
}
@pdaoust
pdaoust / SassMeister-input.scss
Created December 5, 2013 23:09
Generated by SassMeister.com.
// ----
// Sass (v3.3.0.rc.1)
// Compass (v0.13.alpha.10)
// ----
@function f-fold($func, $list, $initial, $args...) {
$start: 1;
@if $initial == null {
// If there's no initial value, use the first in the list.
$start: 2;
@pdaoust
pdaoust / SassMeister-input.scss
Created December 5, 2013 23:03
Generated by SassMeister.com.
// ----
// Sass (v3.3.0.rc.1)
// Compass (v0.13.alpha.10)
// ----
// Filter items from a list. Each function takes an item (and additional
// arguments) and returns a boolean value indicating whether the item passed the
// filter.
@function f-filter($func, $list, $args...) {
$new-list: ();
@pdaoust
pdaoust / SassMeister-input.scss
Created December 5, 2013 22:57
Generated by SassMeister.com.
// ----
// Sass (v3.3.0.rc.1)
// Compass (v0.13.alpha.10)
// ----
// 'map', 'transform', 'select', or 'project' function. Iterate over a list,
// performing a function on each item, and collecting the new items. Each
// function takes an item as a first argument and returns a transformed item.
// You can pass additional arguments to the function too, which is a decent poor
// man's function composition.
@pdaoust
pdaoust / higher-order-functions.scss
Last active April 5, 2023 11:07
Higher-order functions for Sass 3.3 -- now that we've got the `call()` function in Sass, we can start to compose functions. We don't have the benefit of anonymous functions, of course, but this is real functional programming, folks!
// 'map', 'transform', 'select', or 'project' function. Iterate over a list,
// performing a function on each item, and collecting the new items. Each
// function takes an item as a first argument and returns a transformed item.
// You can pass additional arguments to the function too, which is a decent poor
// man's function composition.
// (I didn't call this f-map because the term 'map' is already used in Sass to
// denote a hash or dictionary.)
@function f-apply($func, $list, $args...) {
$new-list: ();
@each $item in $list {