Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating the documentation snippets used #30

Merged
merged 1 commit into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 6 additions & 20 deletions Events.ark
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
(import "List.ark")

###
# @meta Events
# @brief Allows to register events listeners and emit events
# =begin
# (let em (events:manager:make))
# (em.on "myType" (fun (value) (print "This is a callback")))
# (em.emit "myType") # => prints "This is a callback" thanks to the registered listener
# =end
# @author https://github.com/fabien-zoccola
##
(let events:manager:make (fun () {
# listeners list
(mut _listeners [])

###
# @brief Checks if a given callback is valid (is a function or a closure)
# @param callback the callback to check
# @details Returns true if the callback is a function/closure, false otherwise
Expand All @@ -24,11 +20,9 @@
# (closure._check_valid 5) # => false
# =end
# @author https://github.com/fabien-zoccola
##
(let _check_valid (fun (callback)
(or (= "Function" (type callback)) (= "Closure" (type callback)) )))
(or (= "Function" (type callback)) (= "Closure" (type callback)))))

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

###
# @brief Emits an event with a value
# @param val the emitted value
# @param typ the type of the emitted event
Expand All @@ -51,7 +43,6 @@
# (closure.emitWith 5 "myType")
# =end
# @author https://github.com/fabien-zoccola
##
(let emitWith (fun (val typ) {
(mut found false)
(list:forEach _listeners (fun (element)
Expand All @@ -61,32 +52,27 @@
})))
found
}))


###
# @brief Emits an event with no value
# @param typ the type of the emitted event
# @details Calls emitWith nil <typ>
# =begin
# (closure.emit "myType")
# =end
# @author https://github.com/fabien-zoccola
##
(let emit (fun (typ)
(emitWith nil typ) ))
(emitWith nil typ)))

###
# @brief Removes all listeners of a given type
# @param typ the type of event to remove from the list
# @details Returns if at least one listener has been removed
# =begin
# (closure.remove_listeners_of_type "myType")
# =end
# @author https://github.com/fabien-zoccola
##
(let removeListenersOfType (fun (typ) {
(let newlist (list:filter _listeners (fun (element)
(!= typ (@ element 0)) )))
(let newlist
(list:filter _listeners (fun (element) (!= typ (@ element 0)))))
(let deleted (!= newlist _listeners))
(set _listeners newlist)
deleted
Expand All @@ -98,11 +84,11 @@

# hidden methods
&_check_valid

# methods
&on
&emit
&emitWith
&removeListenersOfType
) ())
}))
}))
15 changes: 3 additions & 12 deletions Exceptions.ark
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
###
# @meta Exceptions
# @brief throw takes a value as its argument and return it to be used by try
# @param _x the value to return
# =begin
# (let error (throw "cannot divide by zero"))
# =end
# @author https://github.com/SuperFola
##
(let throw (fun (_x)
(fun (_injl _injr &_x) (_injl _x))
))
(fun (_injl _injr &_x) (_injl _x))))

###
# @brief return takes a value as its argument and return it to be used by try
# @param _x the value to return
# =begin
# (let value (return (/ 1 x)))
# =end
# @author https://github.com/SuperFola
##
(let return (fun (_y)
(fun (_injl _injr &_y) (_injr _y))
))
(fun (_injl _injr &_y) (_injr _y))))

###
# @brief Takes a value either returned by throw or return and apply a given on it if it's an error or not
# @param _either the value to test
# @param _continue the success handler
Expand All @@ -38,6 +30,5 @@
# (fun (err) (print err)))
# =end
# @author https://github.com/SuperFola
##
(let try (fun (_either _continue _handle)
(_either _handle _continue)))
(_either _handle _continue)))
18 changes: 3 additions & 15 deletions Functional.ark
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
###
# @meta Functional
# @brief Compose function calls
# @param _f the first function
# @param _g the second function
Expand All @@ -10,37 +8,29 @@
# (print (composed 12)) # return value is (12 + 12) * (12 + 12)
# =end
# @author https://github.com/rstefanic
##
(let compose (fun (_f _g)
(fun (_y &_f &_g) (_f (_g _y)))))

###
# @brief Take a value as its argument and return a function taking 2 arguments which will call the first function on the value
# @param _x the value
# =begin
# (let val (left 12))
# (val (fun (x) (print x " i am called")) (fun (x) (print x " i am NOT called")))
# =end
# @author https://github.com/SuperFola
##
(let left (fun (_x)
(fun (_injl _injr &_x) (_injl _x))
))
(fun (_injl _injr &_x) (_injl _x))))

###
# @brief Take a value as its argument and return a function taking 2 arguments which will call the second function on the value
# @param _y the value
# =begin
# (let val (right 12))
# (val (fun (x) (print x " i am NOT called")) (fun (x) (print x " i am called")))
# =end
# @author https://github.com/SuperFola
##
(let right (fun (_y)
(fun (_injl _injr &_y) (_injr _y))
))
(fun (_injl _injr &_y) (_injr _y))))

###
# @brief Flip the arguments of a function
# @param _f the function
# @param _a the first argument
Expand All @@ -49,8 +39,6 @@
# (let foo (fun (a b) (- a b)))
# ((flip foo 14) 12) # will call (foo 12 14) instead of (foo 14 12)
# =end

# @author https://github.com/rstefanic
##
(let flip (fun (_f _a)
(fun (_b &_f &_a) (_f _b _a))))
(fun (_b &_f &_a) (_f _b _a))))
Loading