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

40
LINES

< > BotCompany Repo | #1032180 // countIterator_inclusive_step - count from a to b (inclusively) with step size

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

Libraryless. Click here for Pure Java version (10148L/56K).

static ItIt<Int> countIterator_inclusive_step(int a, int b, int step) {
  assertTrue("step > 0", step > 0);
  
  ret new ItIt<Int>() {
    int i = a;
    
    public bool hasNext() { ret i <= b; }
    public Int next() { var j = i; i += step; ret j; }
  };
}

static ItIt<Long> countIterator_inclusive_step(long a, long b, long step) {
  assertTrue("step > 0", step > 0);
  
  ret new ItIt<Long>() {
    long i = a;
    
    public bool hasNext() { ret i <= b; }
    public Long next() { var j = i; i += step; ret j; }
  };
}

static ItIt<Double> countIterator_inclusive_step(double a, double b, double step) {
  assertTrue("step > 0", step > 0);
  
  ret new ItIt<Double>() {
    double i = a;
    
    public bool hasNext() { ret i <= b; }
    public Double next() { var j = i; i += step; ret j; }
  };
}

static <A> ItIt<A> countIterator_inclusive_step(double a, double b, double step, IF1<Double, A> f) {
  ret mapI_if1(f, countIterator_inclusive_step(a, b, step));
}

static <A> ItIt<A> countIterator_inclusive_step(int a, int b, int step, IF1<Int, A> f) {
  ret mapI_if1(f, countIterator_inclusive_step(a, b, step));
}

Author comment

Began life as a copy of #1018110

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx

No comments. add comment

Snippet ID: #1032180
Snippet name: countIterator_inclusive_step - count from a to b (inclusively) with step size
Eternal ID of this version: #1032180/6
Text MD5: 3bb0152b42ac5cf1396306114d48f841
Transpilation MD5: 7ac5e17297b6da6ab2dfbdb37bf37dff
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-01-21 20:33:13
Source code size: 1165 bytes / 40 lines
Pitched / IR pitched: No / No
Views / Downloads: 202 / 284
Version history: 5 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)