I was solving today's leetcode problem, here's a simple example:

*Input: nums = [-4,-1,0,3,10], (the input array is always sorted)*

*Output: [0,1,9,16,100]*

*Explanation: After squaring, the array becomes [16,1,0,9,100].*

*After sorting, it becomes [0,1,9,16,100].*

Trying to solve it in linear time, I realized I would have to combine two slices/iterators based on item magnitudes. I tried looking for an ergonomic iterator-combining function, however, having found nothing I ended up writing it myself. Here's `conditional_interleave`

and how I used it to solve the problem:

```
impl Solution {
pub fn sorted_squares(nums: Vec<i32>) -> Vec<i32> {
let partition_point = nums.partition_point(|&x| x < 0);
let negative = nums[0..partition_point].iter().rev();
let positive = nums[partition_point..].iter();
negative
.conditional_interleave(positive, |a, b| a.abs() < b.abs())
.map(|x| x * x)
.collect()
}
}
```

See implementation in the (Playground).

I am interested whether:

- there is a standard way to achieve the same result,
- and whether this is a good implementation of the idea.

Finally, (I may be reaching here), would this be a good addition to the standard library?

I often need something like this. Another use case that comes to mind is merging sub-arrays in standard merge sort.