Skip to content
This repository has been archived by the owner on Jan 11, 2019. It is now read-only.

Commit

Permalink
Move update method from Map to Iterable
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Pluckthun committed Dec 29, 2016
1 parent 46ffd7f commit 6a2554f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/Iterable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Reducer,
Option,
Transform,
Updater,
Dict
} from './constants'

Expand Down Expand Up @@ -48,6 +49,11 @@ abstract class Iterable<K, T> {
return !this.size
}

update(key: K, updater: Updater<T>): Iterable<K, T> {
const value = this.get(key) as T
return this.set(key, updater(value))
}

forEach(sideEffect: (value: T, key: K) => void) {
this.__iterate((value: T, key: K) => {
sideEffect(value, key)
Expand Down
7 changes: 1 addition & 6 deletions src/Map.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Predicate, Transform, Updater, Option } from './constants'
import { Predicate, Transform, Option } from './constants'
import hash from './util/hash'
import BitmapIndexedNode, { emptyNode } from './kvHamt/BitmapIndexedNode'
import Iterable from './Iterable'
Expand Down Expand Up @@ -85,11 +85,6 @@ export default class Map<K, T> extends Iterable<K, T> {
return makeMap<K, T>(root)
}

update(key: K, updater: Updater<T>): Iterable<K, T> {
const value = this.get(key) as T
return this.set(key, updater(value))
}

map<G>(transform: Transform<K, T, G>): Map<K, G> {
const root = this.root.map<G>(transform, this.owner) as BitmapIndexedNode<K, G>
if (this.owner) {
Expand Down

0 comments on commit 6a2554f

Please sign in to comment.