Skip to content

Instantly share code, notes, and snippets.

@pascalduez
Created May 9, 2014 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pascalduez/2f37293903c9900f2781 to your computer and use it in GitHub Desktop.
Save pascalduez/2f37293903c9900f2781 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.3.7)
// Compass (v1.0.0.alpha.18)
// ----
// A Sass `map-fetch` function
@function head($list) {
@return nth($list, 1);
}
@function tail($list) {
$return: ();
@for $i from 2 through length($list) {
$return: append($return, nth($list, $i));
}
@return $return;
}
// Recursively fetch deep value from nested map.
// -----------------------------------------------------------------------------
// @param [map] $map
// @param [list] $list
// -----------------------------------------------------------------------------
// @return [literal]
@function map-fetch($map, $keys) {
$value: map-get($map, head($keys));
@if (length($keys) > 1) {
@return map-fetch($value, tail($keys));
}
@else {
@return $value;
}
}
Sass {
$map: (
one: (
two: (
three: "yeah!"
)
)
);
test: map-fetch($map, one two three);
}
Sass {
test: "yeah!";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment