Issue 9887 - std.array.insertOrdered?
Summary: std.array.insertOrdered?
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-05 16:19 UTC by bearophile_hugs
Modified: 2024-12-01 16:17 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2013-04-05 16:19:24 UTC
This is a way to insert an item in a sorted array:


import std.stdio: writeln;
import std.range: assumeSorted;
import std.array: insertInPlace;
void main() {
    int[] arr = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90];
    int x = 35;
    arr.insertInPlace(arr.assumeSorted.lowerBound(x).length, x);
    arr.writeln;
}


Haskell has the insert/insertBy functions (for lists):
http://zvon.org/other/haskell/Outputlist/insertBy_f.html  
http://zvon.org/other/haskell/Outputlist/insert_f.html

It's an operation not too much rare, and implementing it correctly like I have shown is not immediate, there is a little risk of introducing a bug. So is it worth adding such small function std.array.insertOrdered() to std.array?
Comment 1 dlangBugzillaToGithub 2024-12-01 16:17:17 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/9968

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB