[Issue 24774] New: Input range + filter + chain => First element vanishes
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Fri Sep 20 12:56:08 UTC 2024
    
    
  
https://issues.dlang.org/show_bug.cgi?id=24774
          Issue ID: 24774
           Summary: Input range + filter + chain => First element vanishes
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: minor
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: qigezx+dc40d6nao940k at grr.la
Chaining another range after a filtered input range omits the first element.
Minimal example:
import std.stdio;
import std.algorithm;
import std.range;
void main(){
        int i = 0;
        int gen(){
                return i++;
        }
        auto r1 = generate!gen.until!(x=> x>10);
        auto r2 = only(100);
        // Will print [7.8,9,10,100]
        // 6 is missing
        r1.filter!"a>5".chain(r2).writeln;
        // By adding "array" before chain, it will behave properly
        // [6,7,8,9,10,100]
        // r1.array.filter!"a>5".chain(r2).writeln;
        // r1.filter!"a>5".array.chain(r2).writeln;
}
>dmd --version
DMD64 D Compiler v2.109.1
Copyright (C) 1999-2024 by The D Language Foundation, All Rights Reserved
written by Walter Bright
os: linux x64
--
    
    
More information about the Digitalmars-d-bugs
mailing list