Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
scheinerman committed Jul 1, 2020
1 parent 18081fe commit 73b7439
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ and values are of `Any` type.

Once a `Bijection`, `b`, is created, we add a new key-value pair in
the same manner as with a `Dict`:
```julia
```
julia> b[1] = "hello"
"hello"
Expand All @@ -42,20 +42,20 @@ julia> b[2] = "bye"
```
Notice, however, that if we add a new key with a value that already
exists in the `Bijection` an error ensues:
```julia
```
julia> b[3] = "hello"
ERROR: One of x or y already in this Bijection
```
Likewise, if a key already has a value it cannot be changed by giving
it a new value:
```julia
```
julia> b[1] = "ciao"
ERROR: One of x or y already in this Bijection
```

If we wish to change the value associated with a given key, the pair
must first be deleted using `delete!`:
```julia
```
julia> delete!(b,1)
Bijection{Any,Any} (with 1 pairs)
Expand All @@ -67,7 +67,7 @@ julia> b[1] = "ciao"

To access a value associated with a given key, we use the same syntax
as for a `Dict`:
```julia
```
julia> b[1]
"ciao"
Expand All @@ -76,7 +76,7 @@ julia> b[2]
```

If the key is not in the `Bijection` an error is raised:
```julia
```
julia> b[3]
ERROR: KeyError: 3 not found
```
Expand All @@ -85,7 +85,7 @@ Since the values in a `Bijection` must be distinct, we can give a
value as an input and retrieve its associate key. The function
`inverse(b,y)` finds the value `x` such that `b[x]==y`. However, we
provide the handy short cut `b(y)`:
```julia
```
julia> b("bye")
2
Expand All @@ -95,7 +95,7 @@ julia> b("ciao")

Naturally, if the requested value is not in the `Bijection` an error
is raised:
```julia
```
julia> b("hello")
ERROR: KeyError: hello not found
```
Expand Down Expand Up @@ -167,7 +167,7 @@ Thinking of a `Bijection` as a mapping between finite sets, we
provide the functions `domain` and `image`. These return,
respectively, the set of keys and the set of values of the
`Bijection`.
```julia
```
julia> domain(b)
Set(Any[2,1])
Expand All @@ -177,22 +177,22 @@ Set(Any["bye","ciao"])

The `collect` function returns the `Bijection` as an array of
key-value pairs:
```julia
```
julia> collect(b)
2-element Array{Tuple{Any,Any},1}:
(2,"bye")
(1,"ciao")
```

The `length` function returns the number of key-value pairs:
```julia
```
julia> length(b)
2
```

The `isempty` function returns `true` exactly when the `Bijection`
contains no pairs:
```julia
```
julia> isempty(b)
false
```
Expand Down

0 comments on commit 73b7439

Please sign in to comment.