MCPcopy Index your code
hub / github.com/bazelbuild/bazel / zip

Method zip

src/main/java/net/starlark/java/eval/MethodLibrary.java:978–1014  ·  view source on GitHub ↗
(Sequence<?> args, StarlarkThread thread)

Source from the content-addressed store, hash-verified

976 }
977
978 @StarlarkMethod(
979 name = "zip",
980 doc =
981 "Returns a <code>list</code> of <code>tuple</code>s, where the i-th tuple contains "
982 + "the i-th element from each of the argument sequences or iterables. The list has "
983 + "the size of the shortest input. With a single iterable argument, it returns a "
984 + "list of 1-tuples. With no arguments, it returns an empty list. Examples:"
985 + "<pre class=\"language-python\">"
986 + "zip() # == []\n"
987 + "zip([1, 2]) # == [(1,), (2,)]\n"
988 + "zip([1, 2], [3, 4]) # == [(1, 3), (2, 4)]\n"
989 + "zip([1, 2], [3, 4, 5]) # == [(1, 3), (2, 4)]</pre>",
990 extraPositionals = @Param(name = "args", doc = "lists to zip."),
991 useStarlarkThread = true)
992 public StarlarkList<?> zip(Sequence<?> args, StarlarkThread thread) throws EvalException {
993 StarlarkList<Tuple> result = StarlarkList.newList(thread.mutability());
994 int ncols = args.size();
995 if (ncols > 0) {
996 Iterator<?>[] iterators = new Iterator<?>[ncols];
997 for (int i = 0; i < ncols; i++) {
998 iterators[i] = Starlark.toIterable(args.get(i)).iterator();
999 }
1000 rows:
1001 for (; ; ) {
1002 Object[] elem = new Object[ncols];
1003 for (int i = 0; i < ncols; i++) {
1004 Iterator<?> it = iterators[i];
1005 if (!it.hasNext()) {
1006 break rows;
1007 }
1008 elem[i] = it.next();
1009 }
1010 result.addElement(Tuple.wrap(elem));
1011 }
1012 }
1013 return result;
1014 }
1015
1016 /** Starlark bool type. */
1017 @StarlarkBuiltin(

Callers

nothing calls this directly

Calls 10

newListMethod · 0.95
toIterableMethod · 0.95
wrapMethod · 0.95
mutabilityMethod · 0.65
getMethod · 0.65
sizeMethod · 0.45
iteratorMethod · 0.45
hasNextMethod · 0.45
nextMethod · 0.45
addElementMethod · 0.45

Tested by

no test coverage detected