already found out!
Solution would be sth like this:
resolveAggregations : Decoder (List Suggestion)
resolveAggregations =
at [ "tags", "by_field", "buckets" ] (list resolveSuggestion)
|> map constructSuggestions
|> map flatten2D
resolveSuggestion : Decoder ( List ( String, Int ), String )
resolveSuggestion =
let
resolveName : Decoder String
resolveName =
at [ "key" ] string
resolveValueAndDocCount : Decoder (List ( String, Int ))
resolveValueAndDocCount =
list (object2 (,) (at [ "key" ] string) (at [ "doc_count" ]
int))
|> at [ "values", "buckets" ]
in
object2 (,)
resolveValueAndDocCount
resolveName
constructSuggestions : List ( List ( String, Int ), String ) -> List (List
Suggestion)
constructSuggestions list =
let
construct : ( List ( String, Int ), String ) -> List Suggestion
construct valuesNameTuple =
let
( values, name ) =
valuesNameTuple
convert : String -> ( String, Int ) -> Suggestion
convert name values =
let
( value, doc_count ) =
values
in
Suggestion name value doc_count
in
List.map (convert name) values
in
List.map construct list
flatten2D : List (List a) -> List a
flatten2D list =
List.foldr (++) [] list
--
You received this message because you are subscribed to the Google Groups "Elm
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.