Associations complement

So I'd like to complement two associations through shared keys... not the best description, so here's an example:

a = <|"a" -> 1, "b" -> 2, "c" -> 3|> b = <|"a" -> 1, "b" -> 5|> 

The questions is, how b differs from a with respect to common keys only, so c doesn't matter.

And by differs I mean, what minimal example of x fulfills:

<|a, x|> ===  <|a, b|> 


I could go with:

Complement @@ [email protected]{b, a} // Association 
<|"b"->5|> 

but stripping associations seems wrong to me. Is there more generic approach?

p.s. in general case one may want to get inf about missing keys too, then:

 Complement @@ Normal @ KeyUnion[{b, a}] 
{"b" -> 5, "c" -> Missing["KeyAbsent", "c"]}  

Replay

Complement seems to work without stripping Association in both cases.

Complement[b, a]
(* <|"b" -> 5|> *)

Complement[Sequence @@ KeyUnion[{b, a}]]
(* <|"b" -> 5, "c" -> Missing["KeyAbsent", "c"]|> *)

What version are you using?

Category: functions Time: 2016-07-30 Views: 10

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.268 (s). 12 q(s)