Angular2 RxJS - Creating an observable for a mocked service
<p>I have a mock file containing a collection of Tasks, each of which has a due date. Currently (below) I have the creation of a simple observable that, when subscribed to, returns the collection of mocked Tasks. What I'm failing to figure out is how I can process the flat array of Tasks to group them by their due date, returning a structure like;</p>

<pre><code>// Current data structure (unstructured)
[{due: "2016-01-01"}, {due: "2016-01-01"}, {due: "2016-01-02"}, ...]

// Desired structure for consumption
{
  "2016-01-01": [{...}, {...}],
  "2016-01-02": [{...}, {...}, {...}],
  "2016-01-03": [{...}]
}
</code></pre>

<p>My current observable creation code is as follows;</p>

<pre><code>// Service...
tasks: Observable&lt;Task[]&gt;;

// init() called from the constructor
private init() {
  this.tasks = Observable.create(observer =&gt; {
    observer.next(mockTasks);
  });
}

getTasks() {
  return this.tasks;
}
</code></pre>

<p>Which is consumed in my component as follows;</p>

<pre><code>// Component...
ngOnInit() {
  this.taskService.getTasks().subscribe(tasks =&gt; {
    this.tasks = tasks; // Contains the collection of tasks as expected
  });
}
</code></pre>

<p>This works fine - I get my full array of tasks back as expected. I've tried using the <code>groupBy</code> operator to achieve the above but the observable created via <code>Observable.create()</code> does not appear to have that method available. I've been referring to <a href="https://www.learnrxjs.io/operators/transformation/groupby.html" rel="noreferrer">this resource</a> to attempt to achieve this and I notice that <code>Observable.from()</code> is used instead of <code>.create()</code>, however this also does not appear to be an available function in my service.</p>

<ol>
<li>Is using RxJS operators (such as <code>groupBy</code>) the way to go with formatting the data as above (and how can this be achieved)? Or should this be manually formatted?</li>
<li>Regarding either answer to 1 - where should this take place?</li>
</ol>

<p>Thanks!</p>