Skip to content

Commit

Permalink
Changed the array flat_map binding to monadic notation, since a monad…
Browse files Browse the repository at this point in the history
…ic array's bind operator is a flat map.
  • Loading branch information
spencertipping committed May 22, 2010
1 parent ee59ef8 commit 2d24b22
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion divergence.rebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
d.map (d.operators, function (_, os) {
d.map (os.transforms, function (nt, vt) {d.functions (d.map (os.operators, function (n, v) {return d.init (nt.fn()(v).maps_to (vt.fn()(v).fn()), nt.fn()(n).maps_to (vt.fn()(v).fn()))}))})});

d.init (Array.prototype, d.map ({'*':'map', '%':'grep', '+':'concat', '/':'fold', '^':'flat_map'}, '$1.maps_to($0[$2])'.fn(Array.prototype)), {'<<':'@push($0), $_'});
d.init (Array.prototype, d.map ({'*':'map', '%':'grep', '+':'concat', '/':'fold', '>>$-':'flat_map'}, '$1.maps_to($0[$2])'.fn(Array.prototype)), {'<<':'@push($0), $_'});

// Divergence inline macro support.
// Divergence promotes strings into functions with a macro mechanism very similar to the one here. Because of this, we can enable code transformation inside those inline macros, including
Expand Down
2 changes: 1 addition & 1 deletion divergence.rebase.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ var d = (function () {
d.map (d.operators, function (_, os) {
d.map (os.transforms, function (nt, vt) {d.functions (d.map (os.operators, function (n, v) {return d.init (nt.fn()(v).maps_to (vt.fn()(v).fn()), nt.fn()(n).maps_to (vt.fn()(v).fn()))}))})});

d.init (Array.prototype, d.map ({'*':'map', '%':'grep', '+':'concat', '/':'fold', '^':'flat_map'}, '$1.maps_to($0[$2])'.fn(Array.prototype)), {'<<':'@push($0), $_'});
d.init (Array.prototype, d.map ({'*':'map', '%':'grep', '+':'concat', '/':'fold', '>>$-':'flat_map'}, '$1.maps_to($0[$2])'.fn(Array.prototype)), {'<<':'@push($0), $_'});

// Divergence inline macro support.
// Divergence promotes strings into functions with a macro mechanism very similar to the one here. Because of this, we can enable code transformation inside those inline macros, including
Expand Down
6 changes: 3 additions & 3 deletions rebase
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ var d = (function () {
__mAHhpP5JgWM51xZULH78ZjhNMuls84Ek6tMtnqKJqRA

meta::code('main', <<'__6KkTHLy+LvTfeOZTBrCzn9rnPMWsBbvlceBXSbnV+8s');
meta::code('main', <<'__p6APu1xK9h+wLTbxkf+GLqs6R3QMbtLbWOiAUn8CJtk');
Divergence Rebase module | Spencer Tipping <spencer@spencertipping.com>
Licensed under the terms of the MIT source code license
Expand Down Expand Up @@ -479,15 +479,15 @@ as a key there (e.g. 'foo'), then it will be sandwiched between binary operators
d.map (d.operators, function (_, os) {
d.map (os.transforms, function (nt, vt) {d.functions (d.map (os.operators, function (n, v) {return d.init (nt.fn()(v).maps_to (vt.fn()(v).fn()), nt.fn()(n).maps_to (vt.fn()(v).fn()))}))})});
d.init (Array.prototype, d.map ({'*':'map', '%':'grep', '+':'concat', '/':'fold', '^':'flat_map'}, '$1.maps_to($0[$2])'.fn(Array.prototype)), {'<<':'@push($0), $_'});
d.init (Array.prototype, d.map ({'*':'map', '%':'grep', '+':'concat', '/':'fold', '>>$-':'flat_map'}, '$1.maps_to($0[$2])'.fn(Array.prototype)), {'<<':'@push($0), $_'});
Divergence inline macro support.
Divergence promotes strings into functions with a macro mechanism very similar to the one here. Because of this, we can enable code transformation inside those inline macros, including
translating operators into method calls, etc. By default this isn't enabled (primarily so that users of this library have a very easy way to disable operator overloading etc.) but you can
enable it like this:
r.enable_inline_macro = (function (enabled) {return function () {enabled || (enabled = !! d.inline_macros.push ('$0.toString()'.compose (r.transform).compose (r.parse)))}}) (false)}) ();
__6KkTHLy+LvTfeOZTBrCzn9rnPMWsBbvlceBXSbnV+8s
__p6APu1xK9h+wLTbxkf+GLqs6R3QMbtLbWOiAUn8CJtk

meta::code('test', <<'__X/r1UDk74aTMshwm5S8DNLa2kvoVo2nrpk987VufUpM');
Divergence Rebase unit tests | Spencer Tipping <spencer@spencertipping.com>
Expand Down

0 comments on commit 2d24b22

Please sign in to comment.