- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
ZipWith[f_, vector1_, vector2_] := Table[ f[ vector1[[i]], vector2[[i]] ], {i, Min[Length[vector1], Length[vector2]] } ]
UnZip[list_] := {Map[First, list], Map[Rest, list]}
Zip[vector1_, vector2_] := ZipWith[{#1, #2} &, vector1, vector2]
ZipWithIndex[vector_] := Zip[vector, Range[1, Length[vector]]]
ZipWithIndexed[f_, vector1_, vector2_] := Map[f @@ # &, Map[Flatten, Zip[vector1, ZipWithIndex[vector2]]]]
Fold2[f_, initialState_, list1_ , list2_ ] := Fold[f @@ Prepend[#2, #1] &, initialState, Zip[list1, list2]]
ZipWith1[f_, {}, any_] := {}
ZipWith1[f_, any_, {}] := {}
ZipWith1[f_, {h1_, t1___}, {h2_, t2___}] := Prepend[ZipWith1[f, {t1}, {t2}], f[h1, h2]]; (*Extremal version, but recursion depth is 256 *)
GroupByIndex[list_, indexesOfGroup_] := (UnZip[#][[1]]) & /@ Gather[ZipWithIndex[list], (And @@ Map[(MemberQ[indexesOfGroup, #]) &, {#1[[2]], #2[[2]]}]) &]