Last active
August 29, 2015 13:56
-
-
Save lunelson/8920028 to your computer and use it in GitHub Desktop.
Additional functions for Sass List Maps
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.2.14) | |
// Compass (v0.12.2) | |
// Sass List-Maps (v0.9.3) | |
// ---- | |
@import "sass-list-maps"; | |
/* | |
EXTRA FUNCTIONS FOR SASS LIST MAPS | |
*/ | |
// map-subvalues() function: retrieves values for key at given depth | |
@function map-subvalues($map, $key, $depth) { | |
$output: (); | |
@if $depth > 1 { @each $tuple in $map { $output: append($output, map-subvalues(value($tuple), $key, $depth - 1)); } } | |
@else { $output: get($map, $key); } | |
@return $output; | |
} | |
$memo-data: (); | |
// helper to chain arguments as a string | |
@function arg-chain($args...) { | |
$output: ('#{nth($args, 1)}'); | |
@for $n from 2 through length($args) { $output: $output + '-#{nth($args, $n)}'; } | |
@return $output; | |
} | |
// memoization pattern | |
@function memoizingFunction($arg1, $arg2) { | |
$memo-key: 'memoizingFunction-' + arg-chain($arg1, $arg2); | |
$memo-val: map-get($memo-data, $memo-key); | |
@if $memo-val { @return $memo-val; } | |
@else { | |
$memo-val: 'TBD'; | |
$memo-data: map-merge-z($memo-data, $memo-key, $memo-val); | |
@return $memo-val; | |
} | |
} |
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
/* | |
EXTRA FUNCTIONS FOR SASS LIST MAPS | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
revision of mq approach; waiting to merge