Thread overview | |||||
---|---|---|---|---|---|
|
November 21, 2019 Splitting a stream of data on based on data change. | ||||
---|---|---|---|---|
| ||||
I was looking through the standard library for a good way to split a range into several ranges based on value changes in the stream: AAAAAAABBBBBB would be split on the AB transition into: AAAAAAA BBBBBB I just couldn't figure out an elegant way to do it? Any ideas? |
November 21, 2019 Re: Splitting a stream of data on based on data change. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Taylor R Hillegeist | On Thursday, 21 November 2019 at 21:36:08 UTC, Taylor R Hillegeist wrote: > I was looking through the standard library for a good way to split a range into several ranges based on value changes in the stream: > > AAAAAAABBBBBB > would be split on the AB transition into: > AAAAAAA BBBBBB > > I just couldn't figure out an elegant way to do it? Any ideas? Like this? ´´´ void main() { import std; "AAAAAAABBBBBB" .chunkBy!((a,b) => a == b) .writeln; } ´´´ https://dlang.org/library/std/algorithm/iteration/group.html https://dlang.org/library/std/algorithm/iteration/chunk_by.html |
November 21, 2019 Re: Splitting a stream of data on based on data change. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alex | On Thursday, 21 November 2019 at 22:11:59 UTC, Alex wrote:
> On Thursday, 21 November 2019 at 21:36:08 UTC, Taylor R Hillegeist wrote:
>> I was looking through the standard library for a good way to split a range into several ranges based on value changes in the stream:
>>
>> AAAAAAABBBBBB
>> would be split on the AB transition into:
>> AAAAAAA BBBBBB
>>
>> I just couldn't figure out an elegant way to do it? Any ideas?
>
> Like this?
>
> ´´´
> void main()
> {
> import std;
> "AAAAAAABBBBBB"
> .chunkBy!((a,b) => a == b)
> .writeln;
> }
> ´´´
>
> https://dlang.org/library/std/algorithm/iteration/group.html
> https://dlang.org/library/std/algorithm/iteration/chunk_by.html
Just like that.
|
Copyright © 1999-2021 by the D Language Foundation