Skip to content

Instantly share code, notes, and snippets.

@thepiwo
Created September 20, 2019 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thepiwo/5a4852f70996eb70b2b968c6cbaef52f to your computer and use it in GitHub Desktop.
Save thepiwo/5a4852f70996eb70b2b968c6cbaef52f to your computer and use it in GitHub Desktop.
namespace List =
function foldr(f : (('a, 'b) => 'b), z: 'b, l : list('a)) : 'b =
switch(l)
[] => z
e :: l' => f(e, foldr(f, z, l'))
contract Identity =
record player = { balance : int }
type state = map(address, player)
entrypoint init() = {}
entrypoint get() = state
stateful entrypoint test() =
let accounts = [ak_2bKhoFWgQ9os4x8CaeDTHZRGzUcSwcXYUrM12gZHKTdyreGRgG, ak_2VnwoJPQgrXvreUx2L9BVvd9BidWwpu1ASKK1AMre21soEgpRT, ak_2bKhoFWgQ9os4x8CaeDTHZRGzUcSwcXYUrM12gZHKTdyreGRgG]
let amount = 100
put(List.foldr(add_player(amount), state, accounts))
function add_player(amount : int) = (account : address, acc : state) =>
state{[account = {balance = 0}] @ player = player{balance @ b = b + amount}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment