Skip to content

Instantly share code, notes, and snippets.

@Undistraction
Created September 11, 2014 22:19
Show Gist options
  • Save Undistraction/388a91d766f1632a5472 to your computer and use it in GitHub Desktop.
Save Undistraction/388a91d766f1632a5472 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.4.3)
// Compass (v1.0.1)
// Sassy Maps (v0.4.0)
// ----
@import "sassy-maps";
$map-1:(
alpha: 1,
beta: 1,
charlie:(
delta: 1,
echo: 1,
foxtrot:(
gamma: 1,
hotel: 1
)
)
);
$map-2:(
alpha: 2,
charlie: (
echo: 2,
foxtrot: (
hotel: 2,
yankee:(
omega: 2
)
)
),
indigo: (
juliette: 2
)
);
// Note that these maps are merged to:
// (
// alpha: 2,
// beta: 1,
// charlie: (
// delta: 1,
// echo: 2,
// foxtrot: (
// gamma: 1,
// hotel: 2,
// yankee: (
// omega: 2
// ),
// indigo: (
// juliette: 2
// )
// )
// )
@function map-merge-deep($map-old, $map-new, $overwrite: true){
// Iterate through each value of the new map
@each $key, $new-value in $map-new {
// Check if that value already exists on the old map
@if map-has-key($map-old, $key) {
// There is an existing key
$old-value: map-get($map-old, $key);
@if type-of($new-value) == map and type-of($old-value) == map {
// If both are maps, recurse regardless of $overwrite
$merged-value: map-merge-deep($old-value, $new-value);
$map-old: map-set($map-old, $key, $merged-value);
}@else{
// Otherwise check $overwrite
@if $overwrite{
$map-old: map-set($map-old, $key, $new-value);
}
}
}@else{
// There is no existing key so add
$map-old: map-set($map-old, $key, $new-value);
}
}
@return $map-old;
}
p::after
{
$map-1: map-merge-deep($map-1, $map-2) !global;
content: "#{map-to-string(map-get-deep($map-1, charlie, foxtrot, yankee, omega))}";
}
p::after {
content: "2";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment