Commit dff3f896 authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

mp_identity(): Add generic identity function.

Useful as getiter method for objects which are their own iterators, etc.
parent 3754c4a0
......@@ -288,3 +288,9 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) {
}
return MP_OBJ_NEW_SMALL_INT(len);
}
// Return input argument. Useful as .getiter for objects which are
// their own iterators, etc.
mp_obj_t mp_identity(mp_obj_t self) {
return self;
}
......@@ -351,6 +351,8 @@ extern const mp_obj_type_t fun_native_type;
extern const mp_obj_type_t fun_bc_type;
void mp_obj_fun_bc_get(mp_obj_t self_in, int *n_args, uint *n_state, const byte **code);
mp_obj_t mp_identity(mp_obj_t self);
// generator
extern const mp_obj_type_t gen_instance_type;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment