Skip to content

Commit 819287c

Browse files
Cokemonkey11Frotty
authored andcommitted
add reference package (#307)
1 parent d3d1d60 commit 819287c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package Reference
2+
/**
3+
A simple wrapper class which contains a reference to a value of the given type.
4+
The main usage is to wrap primitives to modify them inside closures.
5+
6+
> let dist_ref = new Reference(0.)
7+
> someList.for_each() (real elem) ->
8+
> if dist_ref.val < 500
9+
> dist_ref.val += elem
10+
11+
Make sure to destroy references if you don't need them anymore.
12+
*/
13+
14+
public class Reference<T:>
15+
T val
16+
17+
construct(T val)
18+
this.val = val

0 commit comments

Comments
 (0)