如何编写将n元组减少为(n-m)-tuple的函数?
例如,我有{
"settings": {
"index": {
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 20
}
},
"analyzer": {
" autocomplete": {
"type": "custom",
"filter": [
"lowercase",
"autocomplete_filter"
],
"tokenizer": "standard"
}
}
},
"refresh_interval": -1,
"number_of_replicas": 1,
"number_of_shards": 4,
"index_analyzer": "default_index",
"search_analyzer": "default_search"
}
},
"mappings": {
"itemsnew": {
"properties": {
"DESCRIPTION_AUTO": {
"index_analyzer": "autocomplete",
"search_analyzer": "standard",
"type": "string"
}
}
}
}
}
并希望获得(a, b, c, d, e)
像
(a, b, c)
答案 0 :(得分:17)
似乎有类似问题的解决方案(例如,Manipulating "arbitrary" tuples),但我强烈建议您考虑更改数据类型,因为元组并不意味着在诸如此类的上下文中使用。元组不是以某种方式迭代元素,而是模式匹配(固定数量)它们。 另一种选择可能是HList数据类型,如我链接到您的问题的答案中所述。