shared/generic_index_chain.js
function couldChain(r, manyIndexes){
	manyIndexes = manyIndexes || 0
	//return isChainLink(r) && isChainLink
	if(r.view === 'property'){
		if(r.schemaType.type === 'set' || r.schemaType.type === 'list' || r.schemaType.type === 'map'){
			//TODO support this case?
			return
		}else{
			return couldChain(r.params[1],manyIndexes+1)
		}
	}else if(r.view === 'one'){
		return couldChain(r.params[0], manyIndexes)
	}else if(r.view === 'mapValue' && r.params[0].view === 'reducing-index' || 
			r.view === 'mapValue' && r.params[0].view === 'multimap'){
		var valueExpr = r.params[1]
		if(valueExpr.type === 'param'){
			if(valueExpr.was && couldChain(valueExpr.was, manyIndexes+1)){
				//console.log('no was: ' + JSON.stringify(valueExpr))
				//return
				valueExpr = valueExpr.was
			}
		}
		return couldChain(valueExpr,manyIndexes+1)
	}else if(r.type === 'param'){
		if(manyIndexes < 2) return
		return r
	}/*else if(r.view === 'each'){
		var subParam = couldChain(r.params[1].expr, 2)
		if(subParam.name === r.params[1].implicits[0]){
			
		}
	}else if(r.type === 'view'){
		var allParams = []
		var has = {}
		r.params.forEach(function(p){
			var pm = couldChain(p, 2)
			if(!pm) allParams = undefined
			if(allParams && !has[pm.name]){
				allParams.push(pm)
				has[pm.name] = true
			}
		})
		if(allParams && allParams.length === 1){
			return allParams[0]
		}
	}*/
}
function couldChain(r, manyIndexes){
	manyIndexes = manyIndexes || 0
	//return isChainLink(r) && isChainLink
	if(r.view === 'property'){
		if(r.schemaType.type === 'set' || r.schemaType.type === 'list' || r.schemaType.type === 'map'){
			//TODO support this case?
			return
		}else{
			return couldChain(r.params[1],manyIndexes+1)
		}
	}else if(r.view === 'one'){
		return couldChain(r.params[0], manyIndexes)
	}else if(r.view === 'mapValue' && r.params[0].view === 'reducing-index' || 
			r.view === 'mapValue' && r.params[0].view === 'multimap'){
		var valueExpr = r.params[1]
		if(valueExpr.type === 'param'){
			if(valueExpr.was && couldChain(valueExpr.was, manyIndexes+1)){
				//console.log('no was: ' + JSON.stringify(valueExpr))
				//return
				valueExpr = valueExpr.was
			}
		}
		return couldChain(valueExpr,manyIndexes+1)
	}else if(r.type === 'param'){
		if(manyIndexes < 2) return
		return r
	}/*else if(r.view === 'each'){
		var subParam = couldChain(r.params[1].expr, 2)
		if(subParam.name === r.params[1].implicits[0]){
			
		}
	}else if(r.type === 'view'){
		var allParams = []
		var has = {}
		r.params.forEach(function(p){
			var pm = couldChain(p, 2)
			if(!pm) allParams = undefined
			if(allParams && !has[pm.name]){
				allParams.push(pm)
				has[pm.name] = true
			}
		})
		if(allParams && allParams.length === 1){
			return allParams[0]
		}
	}*/
}
/*
function isChainLink(r, key){
if(r.view === 'property' || r.view === 'one') return true
if(r.view === 'mapValue' && r.params[0].view === 'multimap'){
return isChainLink(r.params[1])
}
}