public static <E> LinkedList<E> merge(List<E> list, F2<E,E,E> f) {
    	LinkedList<E> ret = new LinkedList<>();
    	for (int i = 0; i < list.size(); ) {
    		E merge = list.get(i);
    		for (int j = i+1;; j++) {
    			if (j == list.size()) {
        			ret.add(merge);
        			i++;
        			break;
    			}
        		E e2 = list.get(j);
        		
        		E merge1 = f.e(merge, e2);
        		if (merge1 != null) {
        			merge = merge1;
        			if (j==list.size() -1) {
        				ret.add(merge);
            			i=j+1;
            			break;
        			}
        		} else {
        			ret.add(merge);
        			i=j;
        			break;
        		}
			}
    		
		}
		return ret;
    }