Ah that's very interesting!
Although I can't seem to switch the values?
What I'm thinking is joining data with the function:
lookup(Data) = lookup(Data)
Then if I pass in a key, and lookup on a map:
lookup(Key)([Key:Value...Rest]) = Value
Or if I pass in a map, then lookup a key:
lookup([Key:Value...Rest])(Key) = Value
Here are my results:
v1(M) = lookup(b)(M)
v2(M) = lookup(M)(b)
v3(K) = lookup(K)({a:1, b:2, c:3})
v4(K) = lookup({a:1, b:2, c:3})(K)
v1({a:1, b:2, c:3}) -> 2 ~Expected
v2({a:1, b:2, c:3}) -> 1 ~Unexpected
v3(b) -> 2 ~Expected
v4(b) -> 1 ~Unexpected
What are your thoughts on this?
A way around this is to switch the parts to a particular order before hand:
lookup({K:V...T})(X) = lookup(X)({K:V...T})
Although this seems a little unintuitive to have to do.
Also without the searching method, you can't catch a situation when you lookup a key which doesn't exist in the map?
lookup(d)({a:1, b:2, c:3}) -> lookup d { a : 1, b : 2, c : 3 } ~What happens
lookup(d)({a:1, b:2, c:3}) -> nil ~What I'd prefer
Cheers.