-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1271 from demergent-labs/1249_functional_motoko_e…
…xamples Updated motoko examples to functional runtime syntax
- Loading branch information
Showing
48 changed files
with
538 additions
and
680 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,32 @@ | ||
import { int, update, Opt, Void, Some, None, Service } from 'azle'; | ||
import { int, None, Opt, Service, Some, update, Void } from 'azle'; | ||
|
||
export default class extends Service { | ||
cell: int = 0n; | ||
let cell: int = 0n; | ||
|
||
@update([int], int) | ||
add(n: int): int { | ||
this.cell += n; | ||
export default Service({ | ||
add: update([int], int, (n) => { | ||
cell += n; | ||
|
||
return this.cell; | ||
} | ||
return cell; | ||
}), | ||
sub: update([int], int, (n) => { | ||
cell -= n; | ||
|
||
@update([int], int) | ||
sub(n: int): int { | ||
this.cell -= n; | ||
return cell; | ||
}), | ||
mul: update([int], int, (n) => { | ||
cell *= n; | ||
|
||
return this.cell; | ||
} | ||
|
||
@update([int], int) | ||
mul(n: int): int { | ||
this.cell *= n; | ||
|
||
return this.cell; | ||
} | ||
|
||
@update([int], Opt(int)) | ||
div(n: int) { | ||
return cell; | ||
}), | ||
div: update([int], Opt(int), (n) => { | ||
if (n === 0n) { | ||
return None; | ||
} else { | ||
this.cell /= n; | ||
return Some(this.cell); | ||
cell /= n; | ||
return Some(cell); | ||
} | ||
} | ||
|
||
@update([], Void) | ||
clearall(): void { | ||
this.cell = 0n; | ||
} | ||
} | ||
}), | ||
clearall: update([], Void, () => { | ||
cell = 0n; | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,15 @@ | ||
import { nat, query, Service, update, Void } from 'azle'; | ||
|
||
export default class extends Service { | ||
counter: nat = 0n; | ||
|
||
@query([], nat) | ||
get(): nat { | ||
return this.counter; | ||
} | ||
|
||
@update([nat], Void) | ||
set(n: nat): void { | ||
this.counter = n; | ||
} | ||
|
||
@update([], Void) | ||
inc(): void { | ||
this.counter += 1n; | ||
} | ||
} | ||
let counter: nat = 0n; | ||
|
||
export default Service({ | ||
get: query([], nat, () => { | ||
return counter; | ||
}), | ||
set: update([nat], Void, (n) => { | ||
counter = n; | ||
}), | ||
inc: update([], Void, () => { | ||
counter += 1n; | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
import { Service, query, text } from 'azle'; | ||
import { query, Service, text } from 'azle'; | ||
|
||
export default class extends Service { | ||
// Say the given phrase. | ||
@query([text], text) | ||
say(phrase: text): text { | ||
export default Service({ | ||
say: query([text], text, (phrase) => { | ||
return phrase; | ||
} | ||
} | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
import { query, Service, Void } from 'azle'; | ||
|
||
export default class extends Service { | ||
@query([], Void) | ||
main(): void { | ||
export default Service({ | ||
main: query([], Void, () => { | ||
console.log('Hello World!'); | ||
} | ||
} | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
import { Service, query, text } from 'azle'; | ||
import { query, Service, text } from 'azle'; | ||
|
||
export default class extends Service { | ||
@query([text], text) | ||
greet(name: string): string { | ||
export default Service({ | ||
greet: query([text], text, (name) => { | ||
return `Hello, ${name}!`; | ||
} | ||
} | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.