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

23
LINES

< > BotCompany Repo | #1018394 // lazilyMap - map list to list lazily (calculating elements on demand & then caching them)

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

Libraryless. Click here for Pure Java version (9550L/54K).

static <A, B> L<B> lambdaMapLike lazilyMap(IF1<A, B> f, L<A> l) {
  ret lazyMap((O) f, l);
}

static L lazilyMap(fO f, fL l) {
  ret new RandomAccessAbstractList {
    final int size = l(l);
    new HashMap<Int, O> data;
    
    public int size() { ret size; }
    public O get(int i) {
      if (data.containsKey(i))
        ret data.get(i);
      O o = callF(f, l.get(i));
      data.put(i, o);
      ret o;
    }
  };
}

static <A, B> L<B> lazilyMap(L<A> l, IF1<A, B> f) {
  ret lazilyMap(f, l);
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1018394
Snippet name: lazilyMap - map list to list lazily (calculating elements on demand & then caching them)
Eternal ID of this version: #1018394/8
Text MD5: 7b9bbc391eae5e9d8816c014bba1c4cb
Transpilation MD5: 59e113851f20ad7db41b50a6edae1eb7
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-06-27 06:18:29
Source code size: 523 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 402 / 515
Version history: 7 change(s)
Referenced in: [show references]