Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

13
LINES

< > BotCompany Repo | #1036537 // moveItemsFirst - move elements to beginning of (cloned) list

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (10058L/55K).

static <A> L<A> moveItemsFirst(Cl<A> itemsToMove, Cl<A> l) {
  if (empty(itemsToMove) || empty(l)) ret asList(l);
  itemsToMove = asSet(itemsToMove);
  var set = asSet(l);
  L<A> out = emptyList(l(l));
  for (a : itemsToMove)
    if (set.contains(a))
      out.add(a);
  for (A a : l)
    if (!itemsToMove.contains(a))
      out.add(a);
  ret out;
}

Author comment

Began life as a copy of #1030795

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): mqqgnosmbjvj, wnsclhtenguj

No comments. add comment

Snippet ID: #1036537
Snippet name: moveItemsFirst - move elements to beginning of (cloned) list
Eternal ID of this version: #1036537/4
Text MD5: 1704a467edf37fdfb2b6d3ec6cbd8df2
Transpilation MD5: 441242b027197d0c93bc399d0fea34d2
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-01-30 20:01:35
Source code size: 361 bytes / 13 lines
Pitched / IR pitched: No / No
Views / Downloads: 95 / 126
Version history: 3 change(s)
Referenced in: [show references]