Skip to content

Commit

Permalink
Adding in [] lookup syntax for sorted-dict
Browse files Browse the repository at this point in the history
  • Loading branch information
Pauan committed Jul 11, 2017
1 parent 0e082f9 commit 5a7df86
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/std/data/sorted-dict.kk
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,19 @@ public fun empty(compare: (k, k) -> order): sorted-dict<k, a> {
Sorted-dict(from-compare(compare), empty)
}

public fun get(dict: sorted-dict<k, a>, key: k): maybe<a> {
public fun [](dict: sorted-dict<k, a>, key: k): maybe<a> {
unsafe-lookup(dict.tree, key, dict.compare).map(snd)
}

// TODO inline this
// TODO maybe it shouldn't include this ?
public fun [](dict: sorted-dict<k, a>, key: k, value: a): sorted-dict<k, a> {
set(dict, key, value)
}

public fun has?(dict: sorted-dict<k, a>, key: k): bool {
// TODO this can be implemented faster
bool(get(dict, key))
bool(dict[key])
}

public fun set(dict: sorted-dict<k, a>, key: k, value: a): sorted-dict<k, a> {
Expand Down

0 comments on commit 5a7df86

Please sign in to comment.