Skip to content

Commit acf7d32

Browse files
committed
Updating the documentation snippets used
1 parent f529a73 commit acf7d32

File tree

10 files changed

+67
-193
lines changed

10 files changed

+67
-193
lines changed

Events.ark

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
(import "List.ark")
22

3-
###
4-
# @meta Events
53
# @brief Allows to register events listeners and emit events
64
# =begin
75
# (let em (events:manager:make))
86
# (em.on "myType" (fun (value) (print "This is a callback")))
97
# (em.emit "myType") # => prints "This is a callback" thanks to the registered listener
108
# =end
119
# @author https://github.com/fabien-zoccola
12-
##
1310
(let events:manager:make (fun () {
1411
# listeners list
1512
(mut _listeners [])
1613

17-
###
1814
# @brief Checks if a given callback is valid (is a function or a closure)
1915
# @param callback the callback to check
2016
# @details Returns true if the callback is a function/closure, false otherwise
@@ -24,11 +20,9 @@
2420
# (closure._check_valid 5) # => false
2521
# =end
2622
# @author https://github.com/fabien-zoccola
27-
##
2823
(let _check_valid (fun (callback)
29-
(or (= "Function" (type callback)) (= "Closure" (type callback)) )))
24+
(or (= "Function" (type callback)) (= "Closure" (type callback)))))
3025

31-
###
3226
# @brief Registers an event listener
3327
# @param typ the type of the event to listen for
3428
# @param callback the function/closure that will be called when an event is emitted
@@ -37,12 +31,10 @@
3731
# (closure.on "myType" (fun (param) ())
3832
# =end
3933
# @author https://github.com/fabien-zoccola
40-
##
4134
(let on (fun (typ callback)
4235
(if (_check_valid callback)
4336
(set _listeners (append _listeners [typ callback])))))
4437

45-
###
4638
# @brief Emits an event with a value
4739
# @param val the emitted value
4840
# @param typ the type of the emitted event
@@ -51,7 +43,6 @@
5143
# (closure.emitWith 5 "myType")
5244
# =end
5345
# @author https://github.com/fabien-zoccola
54-
##
5546
(let emitWith (fun (val typ) {
5647
(mut found false)
5748
(list:forEach _listeners (fun (element)
@@ -61,32 +52,27 @@
6152
})))
6253
found
6354
}))
64-
6555

66-
###
6756
# @brief Emits an event with no value
6857
# @param typ the type of the emitted event
6958
# @details Calls emitWith nil <typ>
7059
# =begin
7160
# (closure.emit "myType")
7261
# =end
7362
# @author https://github.com/fabien-zoccola
74-
##
7563
(let emit (fun (typ)
76-
(emitWith nil typ) ))
64+
(emitWith nil typ)))
7765

78-
###
7966
# @brief Removes all listeners of a given type
8067
# @param typ the type of event to remove from the list
8168
# @details Returns if at least one listener has been removed
8269
# =begin
8370
# (closure.remove_listeners_of_type "myType")
8471
# =end
8572
# @author https://github.com/fabien-zoccola
86-
##
8773
(let removeListenersOfType (fun (typ) {
88-
(let newlist (list:filter _listeners (fun (element)
89-
(!= typ (@ element 0)) )))
74+
(let newlist
75+
(list:filter _listeners (fun (element) (!= typ (@ element 0)))))
9076
(let deleted (!= newlist _listeners))
9177
(set _listeners newlist)
9278
deleted
@@ -98,11 +84,11 @@
9884

9985
# hidden methods
10086
&_check_valid
101-
87+
10288
# methods
10389
&on
10490
&emit
10591
&emitWith
10692
&removeListenersOfType
10793
) ())
108-
}))
94+
}))

Exceptions.ark

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
1-
###
2-
# @meta Exceptions
31
# @brief throw takes a value as its argument and return it to be used by try
42
# @param _x the value to return
53
# =begin
64
# (let error (throw "cannot divide by zero"))
75
# =end
86
# @author https://github.com/SuperFola
9-
##
107
(let throw (fun (_x)
11-
(fun (_injl _injr &_x) (_injl _x))
12-
))
8+
(fun (_injl _injr &_x) (_injl _x))))
139

14-
###
1510
# @brief return takes a value as its argument and return it to be used by try
1611
# @param _x the value to return
1712
# =begin
1813
# (let value (return (/ 1 x)))
1914
# =end
2015
# @author https://github.com/SuperFola
21-
##
2216
(let return (fun (_y)
23-
(fun (_injl _injr &_y) (_injr _y))
24-
))
17+
(fun (_injl _injr &_y) (_injr _y))))
2518

26-
###
2719
# @brief Takes a value either returned by throw or return and apply a given on it if it's an error or not
2820
# @param _either the value to test
2921
# @param _continue the success handler
@@ -38,6 +30,5 @@
3830
# (fun (err) (print err)))
3931
# =end
4032
# @author https://github.com/SuperFola
41-
##
4233
(let try (fun (_either _continue _handle)
43-
(_either _handle _continue)))
34+
(_either _handle _continue)))

Functional.ark

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
###
2-
# @meta Functional
31
# @brief Compose function calls
42
# @param _f the first function
53
# @param _g the second function
@@ -10,37 +8,29 @@
108
# (print (composed 12)) # return value is (12 + 12) * (12 + 12)
119
# =end
1210
# @author https://github.com/rstefanic
13-
##
1411
(let compose (fun (_f _g)
1512
(fun (_y &_f &_g) (_f (_g _y)))))
1613

17-
###
1814
# @brief Take a value as its argument and return a function taking 2 arguments which will call the first function on the value
1915
# @param _x the value
2016
# =begin
2117
# (let val (left 12))
2218
# (val (fun (x) (print x " i am called")) (fun (x) (print x " i am NOT called")))
2319
# =end
2420
# @author https://github.com/SuperFola
25-
##
2621
(let left (fun (_x)
27-
(fun (_injl _injr &_x) (_injl _x))
28-
))
22+
(fun (_injl _injr &_x) (_injl _x))))
2923

30-
###
3124
# @brief Take a value as its argument and return a function taking 2 arguments which will call the second function on the value
3225
# @param _y the value
3326
# =begin
3427
# (let val (right 12))
3528
# (val (fun (x) (print x " i am NOT called")) (fun (x) (print x " i am called")))
3629
# =end
3730
# @author https://github.com/SuperFola
38-
##
3931
(let right (fun (_y)
40-
(fun (_injl _injr &_y) (_injr _y))
41-
))
32+
(fun (_injl _injr &_y) (_injr _y))))
4233

43-
###
4434
# @brief Flip the arguments of a function
4535
# @param _f the function
4636
# @param _a the first argument
@@ -49,8 +39,6 @@
4939
# (let foo (fun (a b) (- a b)))
5040
# ((flip foo 14) 12) # will call (foo 12 14) instead of (foo 14 12)
5141
# =end
52-
5342
# @author https://github.com/rstefanic
54-
##
5543
(let flip (fun (_f _a)
56-
(fun (_b &_f &_a) (_f _b _a))))
44+
(fun (_b &_f &_a) (_f _b _a))))

0 commit comments

Comments
 (0)