mp_identity(): Add generic identity function.

Useful as getiter method for objects which are their own iterators, etc.
genexit-inst
Paul Sokolovsky 2014-01-20 18:37:30 +02:00
parent 3754c4a040
commit dff3f896d7
2 changed files with 8 additions and 0 deletions

View File

@ -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;
}

View File

@ -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;