Skip to content

Instantly share code, notes, and snippets.

@pentzzsolt
Last active July 1, 2020 19:43
Show Gist options
  • Select an option

  • Save pentzzsolt/4949bbd7691d43d00616dc4f1451cae9 to your computer and use it in GitHub Desktop.

Select an option

Save pentzzsolt/4949bbd7691d43d00616dc4f1451cae9 to your computer and use it in GitHub Desktop.
Example code for my non-destructive-map-merge Sass function.
@function non-destructive-map-merge($parent-map, $child-map) {
$result: $parent-map;
@each $key, $value in $child-map {
@if (not map-has-key($result, $key)) or (type-of(map-get($result, $key)) != type-of($value)) or (not (type-of(map-get($result, $key)) == map and type-of($value) == map)) {
$result: map-merge($result, ($key: $value));
}
@else {
$result: map-merge($result, ($key: non-destructive-map-merge(map-get($result, $key), $value)));
}
}
@return $result;
}
@mmjaeger

mmjaeger commented Sep 1, 2016

Copy link
Copy Markdown

Hello
Glad I found your function - however I'm having an issue with it and I was wondering whether there is a way to change the order of the resulting map:

I basically have something like this: @include grid-column($width: (xs: 2, md: 4, lg: 4), $offset: (md: 6, lg: 3));

I currently end up with:
$map: ( lg: ( width: 4, offset: 3 ), md: ( width: 4, offset: 6 ), xs: ( width: 2 ) );

However, I'd like to get this at the end:
$map: ( xs: ( width: 2 ), md: ( width: 4, offset: 6 ), lg: ( width: 4, offset: 3 ) );

what am I missing - hope you got an idea.

Thank you in advance for your input

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment