Skip to content

Commit ed2c45e

Browse files
committed
Comments
1 parent 2667b3f commit ed2c45e

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

mainframe/frame.hpp

+51
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,32 @@ class frame
213213
frame<Ts..., T>
214214
append_column(const std::string& column_name) const;
215215

216+
/// Add a new column to the end of the frame with type T and initialize it
217+
/// with a callable object like an expression
218+
///
219+
/// frame<year_month, int> f1;
220+
/// f1.set_column_names({"month", "length"});
221+
/// f1.push_back(2022_y/1, 1);
222+
/// f1.push_back(2022_y/2, 2);
223+
/// f1.push_back(2022_y/3, 3);
224+
/// frame<year_month, int, double> f2 = f1.append_column<double>("depth", _1 + 10.0);
225+
/// // f2 is now
226+
/// // | month | length | depth
227+
/// // __|_________|________|_______
228+
/// // 0| 2022-01 | 1 | 11.0
229+
/// // 1| 2022-02 | 2 | 12.0
230+
/// // 2| 2022-03 | 3 | 13.0
231+
/// frame<year_month, int, double> f3 =
232+
/// f2.append_column<double>("height", [](auto& beginit, auto& currit, auto& endit) {
233+
/// return currit->at(_1) + 20.0;
234+
/// });
235+
/// // f3 is now
236+
/// // | month | length | depth | height
237+
/// // __|_________|________|_______|________
238+
/// // 0| 2022-01 | 1 | 11.0 | 21.0
239+
/// // 1| 2022-02 | 2 | 12.0 | 22.0
240+
/// // 2| 2022-03 | 3 | 13.0 | 23.0
241+
///
216242
template<typename T, typename Ex>
217243
frame<Ts..., T>
218244
append_column(const std::string& column_name, Ex expr) const;
@@ -474,6 +500,31 @@ class frame
474500
frame<T, Ts...>
475501
prepend_column(const std::string& column_name) const;
476502

503+
/// Add a new column to the beginning of the frame with type Tand initialize it
504+
/// with a callable object like an expression
505+
///
506+
/// frame<year_month, int> f1;
507+
/// f1.set_column_names({"month", "length"});
508+
/// f1.push_back(2022_y/1, 1);
509+
/// f1.push_back(2022_y/2, 2);
510+
/// f1.push_back(2022_y/3, 3);
511+
/// frame<double, year_month, int> f2 = f1.prepend_column<double>("depth", _1 + 10.0);
512+
/// // f2 is now
513+
/// // | depth | month | length
514+
/// // __|_______|_________|________
515+
/// // 0| 11.0 | 2022-01 | 1
516+
/// // 1| 12.0 | 2022-02 | 2
517+
/// // 2| 13.0 | 2022-03 | 3
518+
/// frame<year_month, int, double> f3 =
519+
/// f2.prepend_column<double>("height", [](auto& beginit, auto& currit, auto& endit) {
520+
/// return currit->at(_2) + 20.0;
521+
/// });
522+
/// // | height | depth | month | length
523+
/// // __|________|_______|_________|________
524+
/// // 0| 21.0 | 11.0 | 2022-01 | 1
525+
/// // 1| 22.0 | 12.0 | 2022-02 | 2
526+
/// // 2| 23.0 | 13.0 | 2022-03 | 3
527+
///
477528
template<typename T, typename Ex>
478529
frame<T, Ts...>
479530
prepend_column(const std::string& column_name, Ex expr) const;

0 commit comments

Comments
 (0)