-
Notifications
You must be signed in to change notification settings - Fork 5
/
classify.cpp
36 lines (31 loc) · 916 Bytes
/
classify.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* Copyright 2019 Joaquin M Lopez Munoz.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See https://github.com/joaquintides/usingstdcpp2019 for talk material.
*/
#include <iostream>
#include <string>
#include "urp.hpp"
int main()
{
using namespace usingstdcpp2019::urp;
trigger<std::string> s;
auto res=hold(
s|group_by([](const std::string& str){return str.c_str()[0];})
|map([](auto e){
return hold(std::move(e)|collect());
})
|collect()
);
auto names={
"John","Jack","Susan","Mary","Anne","Anthony","Bjarne","Margaret",
"George","Barack","Sarah","Peter","Hillary","Ronda","Alice","Herbert",
};
for(const auto& str:names)s=str;
for(const auto& e:res.get()){
for(const auto& str:e.get())std::cout<<str<<" ";
std::cout<<"\n";
}
}