-
Notifications
You must be signed in to change notification settings - Fork 9
Implement TaskSeq.insertAt
, updateAt
, removeAt
, insertManyAt
, removeManyAt
#236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
5f0d5dd
077c355
42269e5
391f438
b641aa6
2a5bbdd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
TaskSeq.removeAt
and TaskSeq.removeManyAt
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1300,3 +1300,29 @@ type TaskSeq = | |
/// <exception cref="T:ArgumentNullException">Thrown when the input task sequence is null.</exception> | ||
/// <exception cref="T:ArgumentException">Thrown when index is below 0 or greater than source length.</exception> | ||
static member insertManyAt: index: int -> values: TaskSeq<'T> -> source: TaskSeq<'T> -> TaskSeq<'T> | ||
|
||
/// <summary> | ||
/// Return a new task sequence with the item at the given index removed. | ||
/// </summary> | ||
/// | ||
/// <param name="index">The index where the item should be removed.</param> | ||
/// <param name="source">The input task sequence.</param> | ||
/// <returns>The result task sequence.</returns> | ||
/// <exception cref="T:ArgumentNullException">Thrown when the input task sequence is null.</exception> | ||
/// <exception cref="T:ArgumentException">Thrown when index is below 0 or greater than source length.</exception> | ||
static member removeAt: index: int -> source: TaskSeq<'T> -> TaskSeq<'T> | ||
|
||
/// <summary> | ||
/// Return a new task sequence with the number of items starting at a given index removed. | ||
/// If <paramref name="count" /> is negative or zero, no items are removed. If <paramref name="index" /> | ||
/// + <paramref name="count" /> is greater than source length, but <paramref name="index" /> is not, then | ||
/// all items until end of sequence are removed. | ||
/// </summary> | ||
/// | ||
/// <param name="index">The index where the items should be removed.</param> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the position from which the items should commence being omitted |
||
/// <param name="count">The number of items to remove.</param> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of the legalese in the summary, maybe this could have a terse hint that negative is treated as zero and a count stretching past the end of the input is safe/ignored? |
||
/// <param name="source">The input task sequence.</param> | ||
/// <returns>The result task sequence.</returns> | ||
/// <exception cref="T:ArgumentNullException">Thrown when the input task sequence is null.</exception> | ||
/// <exception cref="T:ArgumentException">Thrown when index is below 0 or greater than source length.</exception> | ||
static member removeManyAt: index: int -> count: int -> source: TaskSeq<'T> -> TaskSeq<'T> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -896,6 +896,43 @@ module internal TaskSeqInternal = | |
raiseOutOfBounds (nameof index) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if this is a dynamic case, like this, is argument exception appropriate? I know I suggested that ArgumentOutOfRangeException might be better too, but it's kinda wrong for the same reasons no? Only raising questions; I assume this is derived from what Seq does/decided... |
||
} | ||
|
||
let removeAt index (source: TaskSeq<'T>) = | ||
if index < 0 then | ||
raiseCannotBeNegative (nameof index) | ||
|
||
taskSeq { | ||
let mutable i = 0 | ||
|
||
for item in source do | ||
if i <> index then | ||
yield item | ||
|
||
i <- i + 1 | ||
|
||
// cannot remove past end of sequence | ||
if i <= index then | ||
raiseOutOfBounds (nameof index) | ||
} | ||
|
||
let removeManyAt index count (source: TaskSeq<'T>) = | ||
if index < 0 then | ||
raiseCannotBeNegative (nameof index) | ||
|
||
taskSeq { | ||
let mutable i = 0 | ||
let indexEnd = index + count | ||
|
||
for item in source do | ||
if i < index || i >= indexEnd then | ||
yield item | ||
|
||
i <- i + 1 | ||
|
||
// cannot remove past end of sequence | ||
if i <= index then | ||
raiseOutOfBounds (nameof index) | ||
} | ||
|
||
// Consider turning using an F# version of this instead? | ||
// https://github.com/i3arnon/ConcurrentHashSet | ||
type ConcurrentHashSet<'T when 'T: equality>(ct) = | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yields a new task sequence omitting the specified number of items at the given index
Am also thinking that the term
position
might make sense somewhere, but you use index consistenly and I think its a good termalso instead of omitting, maybe dropping?