Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
implicit-explicit comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
novusnota committed Mar 12, 2024
1 parent 300dd2e commit db48f03
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion pages/book/cookbook.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,23 @@ let hasNoData: Bool = slice_with_data.dataEmpty(); // true

### How to determine if Slices are equal

Direct comparison:

```tact
let firstSlice: Slice = "A".asSlice();
let secondSlice: Slice = "A".asSlice();
let areEqual: Bool = firstSlice == secondSlice;
let areNotEqual: Bool = firstSlice != secondSlice;
dump(areEqual) // true;
dump(areNotEqual) // false;
```

Note, that direct comparison via `=={:tact}` or `!={:tact}` operators implicitly uses hashes under the hood.

Explicit comparisons using `.hash(){:tact}` are also available:

```tact
fun areSlicesEqual(a: Slice, b: Slice): Bool {
return a.hash() == b.hash();
Expand Down Expand Up @@ -258,7 +275,24 @@ slice.empty();

### How to determine if Cells are equal

We can easily determine Cell equality based on their hash.
Direct comparison:

```tact
let a: Cell = beginCell()
.storeUint(123, 16)
.endCell();
let b: Cell = beginCell()
.storeUint(123, 16)
.endCell();
let areCellsEqual: Bool = a == b; // true
let areCellsNotEqual: Bool = a != b; // false
```

Note, that direct comparison via `=={:tact}` or `!={:tact}` operators implicitly uses hashes under the hood.

Explicit comparisons using `.hash(){:tact}` are also available:

```tact
let a: Cell = beginCell()
Expand All @@ -270,6 +304,7 @@ let b: Cell = beginCell()
.endCell();
let areCellsEqual: Bool = a.hash() == b.hash(); // true
let areCellsNotEqual: Bool = a.hash() != b.hash(); // false
```

<Callout>
Expand Down

0 comments on commit db48f03

Please sign in to comment.