Skip to content

Instantly share code, notes, and snippets.

@pdaoust
Created December 5, 2013 23:09
Show Gist options
  • Save pdaoust/7815719 to your computer and use it in GitHub Desktop.
Save pdaoust/7815719 to your computer and use it in GitHub Desktop.
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;
$initial: nth($list, 1);
}
$prev: $initial;
@for $i from $start through length($list) {
$next: nth($list, $i);
$prev: call($func, $prev, $next, $args...);
}
@return $prev;
}
@function join-with-separator($val1, $val2, $separator) {
@return "#{$val1}#{$separator}#{$val2}";
}
p {
joined: join-with-separator("About", "Links", " | ");
many-joined: f-fold(join-with-separator, ("Home" "About" "Links" "Contact"), null, " | ");
}
p {
joined: "About | Links";
many-joined: "Home | About | Links | Contact";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment