Created
May 9, 2014 16:09
-
-
Save pascalduez/2f37293903c9900f2781 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---- | |
// 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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sass { | |
test: "yeah!"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment