From ff4556a4cfbcd63e216d505a3637465866e0907e Mon Sep 17 00:00:00 2001 From: yiinho Date: Wed, 3 Dec 2014 16:38:50 -0800 Subject: [PATCH 1/3] Null check before walk to handle null values I.e. previously edn.unify('{:x nil :y ?xxx}', '{:xxx 42}'); was failing due to null not having 'walk' as a member function. With this change I confirmed the said example works fine. --- src/collections.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/collections.coffee b/src/collections.coffee index bff2770..42ca8b1 100644 --- a/src/collections.coffee +++ b/src/collections.coffee @@ -158,7 +158,7 @@ class Map walk: (iter) -> @map (v, k) -> - if type(v.walk) is "function" + if type(v?.walk) is "function" iter (v.walk iter), k else iter v, k From 5c9e7041e7eece97e30835a385890ca0c2dbd31b Mon Sep 17 00:00:00 2001 From: yiinho Date: Wed, 3 Dec 2014 16:47:26 -0800 Subject: [PATCH 2/3] Update compiled js file to reflect null check change --- lib/collections.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/collections.js b/lib/collections.js index 901a0d7..992289a 100644 --- a/lib/collections.js +++ b/lib/collections.js @@ -339,7 +339,7 @@ Map.prototype.walk = function(iter) { return this.map(function(v, k) { - if (type(v.walk) === "function") { + if (type(v != null ? v.walk : void 0) === "function") { return iter(v.walk(iter), k); } else { return iter(v, k); From e25b97208c9e0033c0473cce43f01498b998e2e6 Mon Sep 17 00:00:00 2001 From: yiinho Date: Wed, 3 Dec 2014 17:05:42 -0800 Subject: [PATCH 3/3] Null check in walk in iterable to mirror that in map --- lib/collections.js | 2 +- src/collections.coffee | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/collections.js b/lib/collections.js index 992289a..477e527 100644 --- a/lib/collections.js +++ b/lib/collections.js @@ -72,7 +72,7 @@ Iterable.prototype.walk = function(iter) { return this.map(function(i) { - if ((i.walk != null) && type(i.walk) === "function") { + if (type(i != null ? i.walk : void 0) === "function") { return i.walk(iter); } else { return iter(i); diff --git a/src/collections.coffee b/src/collections.coffee index 42ca8b1..4b43166 100644 --- a/src/collections.coffee +++ b/src/collections.coffee @@ -27,7 +27,7 @@ class Iterable extends Prim walk: (iter) -> @map (i) -> - if i.walk? and type(i.walk) is "function" + if type(i?.walk) is "function" i.walk iter else iter i