Skip to content

Instantly share code, notes, and snippets.

@jgouly
Created July 3, 2009 10:10
Show Gist options
  • Save jgouly/140041 to your computer and use it in GitHub Desktop.
Save jgouly/140041 to your computer and use it in GitHub Desktop.
*** ../why-potion-4476f678fd22706ada7acf2c425c9336328b38c5/core/table.c 2009-07-01 00:07:26.000000000 +0100
--- core/table.c 2009-07-03 12:03:20.000000000 +0100
*************** PN potion_tuple_put(Potion *P, PN cl, PN
*** 204,209 ****
--- 204,220 ----
return potion_table_put(P, PN_NIL, potion_table_cast(P, self), key, value);
}
+ PN potion_tuple_map2(Potion *P, PN cl, PN self, PN block) {
+ PN_TUPLE_EACH(self, i, v, {
+ potion_tuple_put(P, cl, self, PN_NUM(i), PN_CLOSURE_F(block)(P, block, self, v));
+ });
+ return self;
+ }
+
+ PN potion_tuple_map(Potion *P, PN cl, PN self, PN block) {
+ return potion_tuple_map2(P, cl, potion_tuple_clone(P, cl, self), block);
+ }
+
PN potion_tuple_print(Potion *P, PN cl, PN self) {
PN_TUPLE_EACH(self, i, v, {
potion_send(v, PN_print);
*************** void potion_table_init(Potion *P) {
*** 265,270 ****
--- 276,283 ----
potion_type_callset_is(tpl_vt, PN_FUNC(potion_tuple_put, "index=N,value=o"));
potion_method(tpl_vt, "at", potion_tuple_at, "index=N");
potion_method(tpl_vt, "each", potion_tuple_each, "index=N");
+ potion_method(tpl_vt, "map2", potion_tuple_map2, "index=N");
+ potion_method(tpl_vt, "map", potion_tuple_map, "index=N");
potion_method(tpl_vt, "clone", potion_tuple_clone, 0);
potion_method(tpl_vt, "first", potion_tuple_first, 0);
potion_method(tpl_vt, "join", potion_tuple_join, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment