Replies: 7 comments
-
|
I like the operator 👍 As to solving the original problem I suggest (apply merge-with merge
(m/search {1 {:en "one", :de "eins", :fr "un"}
2 {:en "two", :de "zwei", :fr "deux" :es "dos"}
3 {:en "three", :de "drei", :fr "trois"}
5 {:fr "cinq"}}
(m/scan [?num (m/scan [?lang ?word])])
{?lang {?num ?word}}))
=>
{:en {1 "one", 2 "two", 3 "three"},
:de {1 "eins", 2 "zwei", 3 "drei"},
:fr {1 "un", 2 "deux", 3 "trois", 5 "cinq"},
:es {2 "dos"}} |
Beta Was this translation helpful? Give feedback.
-
|
I've changed my mind based on recent experiments; I think the current definition of Specifically:
|
Beta Was this translation helpful? Give feedback.
-
(m/match {}
(map-of !x !y)
[!x !y])Is an error: When matching, map patterns may not contain variables in their keys that would make it so there is more than one match possible. |
Beta Was this translation helpful? Give feedback.
-
|
@timothypratley Thats expected behavior. |
Beta Was this translation helpful? Give feedback.
-
|
Sure! Expected behavior given the definition, but don't you think it limits what it can be used for?
It looks like the intention is a convenience to gathering key-value pairs, but I claim that is better served by Is there a property of |
Beta Was this translation helpful? Give feedback.
-
|
As a (m/rewrite {:a :b :c :d :e :f}
{& (m/seqable [!k !v] ..!n)}
{& ([!k !v] ..!n)})It is almost symetrical and almost as concise as (m/match {1 {:en "one", :de "eins", :fr "un"}
2 {:en "two", :de "zwei", :fr "deux" :es "dos"}
3 {:en "three", :de "drei", :fr "trois"}
5 {:fr "cinq"}}
{& (m/seqable [!num {& (m/seqable [!lang !word] ..!partition)}] ...)}
{:num !num
:lang !lang
:word !word
:partitions !partition})
#_#_=>
{:num [1 2 3 5],
:lang [:en :de :fr :en :de :fr :es :en :de :fr :fr],
:word ["one" "eins" "un" "two" "zwei" "deux" "dos" "three" "drei" "trois" "cinq"],
:partitions [3 4 3 1]}I think |
Beta Was this translation helpful? Give feedback.
-
|
There's a pull request open for For grouping, we have a solution on ;; Tally
(m/fold m* 0 +)
;; Max
(m/fold m* 0 clojure.core/max)Here is an example of how it works: (m/find [1 8 9 -1 10 30 3]
(m/with [%min (m/fold *min 0 clojure.core/min)]
[%min ...])
*min)
;; => -1Of course, this can be used to do grouping as well since grouping is a reduction. It may be possible to bring |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This was prompted by a question on the Slack channel on how to match and substitute maps which represent homogeneous, variable-length mappings instead of a heterogeneous collection of keys.
The example I had in mind was how to transform the nested data structure
into the following result
{:en {1 "one", 2 "two", 3 "three"} :de {1 "eins", 2 "zwei", 3 "drei"} :fr {1 "un", 2 "deux", 3 "trois", 5 "cinq"} :es {2 "dos"}}It turns out this example conflates a "database join", or grouping operation which may be a separate and more challenging problem.
The
map-ofimplementation @noprompt suggested:The operator in use, and partial solution to the original problem:
Beta Was this translation helpful? Give feedback.
All reactions