Skip to content

Commit 6972e80

Browse files
committed
make read-only types return in-memory data for write operations
1 parent f1e988c commit 6972e80

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

src/xitdb/array_list.clj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
(count [_]
1919
(.count ral))
2020

21-
(cons [_ o]
22-
(throw (UnsupportedOperationException. "XITDBArrayList is read-only")))
21+
(cons [this o]
22+
(cons o (common/materialize this)))
2323

24-
(empty [_]
25-
(throw (UnsupportedOperationException. "XITDBArrayList is read-only")))
24+
(empty [this]
25+
[])
2626

2727
(equiv [this other]
2828
(and (sequential? other)
@@ -33,7 +33,7 @@
3333

3434
clojure.lang.IPersistentVector
3535
(assocN [this i val]
36-
(throw (UnsupportedOperationException. "XITDBArrayList is read-only")))
36+
(assoc (common/materialize this) i val))
3737

3838
(length [this]
3939
(.count ral))

src/xitdb/hash_map.clj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@
3535
(clojure.lang.MapEntry. key v))))
3636

3737
(assoc [this k v]
38-
(throw (UnsupportedOperationException. "XITDBHashMap is read-only")))
38+
(assoc (common/materialize this) k v))
3939

4040
clojure.lang.IPersistentMap
41-
(without [_ _]
42-
(throw (UnsupportedOperationException. "XITDBHashMap is read-only")))
41+
(without [this k]
42+
(dissoc (common/materialize this) k))
4343

4444
(count [this]
4545
(operations/map-item-count rhm))
4646

4747
clojure.lang.IPersistentCollection
48-
(cons [_ _]
49-
(throw (UnsupportedOperationException. "XITDBHashMap is read-only")))
48+
(cons [this o]
49+
(cons o (common/materialize this)))
5050

51-
(empty [_]
52-
(throw (UnsupportedOperationException. "XITDBHashMap is read-only")))
51+
(empty [this]
52+
{})
5353

5454
(equiv [this other]
5555
(and (instance? clojure.lang.IPersistentMap other)

src/xitdb/hash_set.clj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
(deftype XITDBHashSet [^ReadHashSet rhs]
1717
clojure.lang.IPersistentSet
18-
(disjoin [_ k]
19-
(throw (UnsupportedOperationException. "XITDBHashSet is read-only")))
18+
(disjoin [this k]
19+
(disj (common/materialize this) k))
2020

2121
(contains [this k]
2222
(operations/set-contains? rhs k))
@@ -26,11 +26,11 @@
2626
k))
2727

2828
clojure.lang.IPersistentCollection
29-
(cons [_ o]
30-
(throw (UnsupportedOperationException. "XITDBHashSet is read-only")))
29+
(cons [this o]
30+
(cons o (common/materialize this)))
3131

32-
(empty [_]
33-
(throw (UnsupportedOperationException. "XITDBHashSet is read-only")))
32+
(empty [this]
33+
#{})
3434

3535
(equiv [this other]
3636
(and (instance? clojure.lang.IPersistentSet other)

src/xitdb/linked_list.clj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
(count [_]
2020
(.count rlal))
2121

22-
(cons [_ o]
23-
(throw (UnsupportedOperationException. "XITDBLinkedArrayList is read-only")))
22+
(cons [this o]
23+
(cons o (common/materialize this)))
2424

25-
(empty [_]
26-
(throw (UnsupportedOperationException. "XITDBLinkedArrayList is read-only")))
25+
(empty [this]
26+
'())
2727

2828
(equiv [this other]
2929
(and (sequential? other)

0 commit comments

Comments
 (0)