Skip to content

Feat doc #2

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

Merged
merged 12 commits into from
Sep 14, 2020
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
45 changes: 45 additions & 0 deletions Exceptions.ark
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
###
# @meta Exceptions
# @brief throw takes a value as its argument and return it to be used by try
# ---
# (let error (throw "cannot divide by zero"))
# ---
# @param _x the value to return
# @author https://github.com/SuperFola
###
(let throw (fun (_x)
(fun (_injl _injr &_x) (_injl _x))
))

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

###
# @meta Exceptions
# @brief Takes a value either returned by throw or return and apply a given on it if it's an error or not
# ---
# (let invert (fun (x)
# (if (= x 0)
# (throw "cannot divide by zero")
# (return (/ 1 x)))))
# (try (invert 0)
# (fun (inverted) (print inverted))
# (fun (err) (print err)))
# ---
# @param _either the value to test
# @param _continue the success handler
# @param _handle the error handler
# @author https://github.com/SuperFola
###
(let try (fun (_either _continue _handle)
(_either _handle _continue)))
58 changes: 58 additions & 0 deletions Functional.ark
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
###
# @meta Functional
# @brief Compose function calls
# ---
# (let foo (fun (a) (* a a)))
# (let bar (fun (b) (+ b b)))
# (let composed (compose foo bar))
# (print (composed 12)) # return value is (12 + 12) * (12 + 12)
# ---
# @param _f the first function
# @param _g the second function
# @author https://github.com/rstefanic
###
(let compose (fun (_f _g)
(fun (_y &_f &_g) (_f (_g _y)))))

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

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

###
# @meta Functional
# @brief Flip the arguments of a function
# @details Returns a function taking 1 argument: the second argument of the function to flip
# ---
# (let foo (fun (a b) (- a b)))
# ((flip foo 14) 12) # will call (foo 12 14) instead of (foo 14 12)
# ---
# @param _f the function
# @param _a the first argument
# @author https://github.com/rstefanic
###
(let flip (fun (_f _a)
(fun (_b &_f &_a) (_f _b _a))))
2 changes: 0 additions & 2 deletions Functional/Compose.ark

This file was deleted.

9 changes: 0 additions & 9 deletions Functional/Drop.ark

This file was deleted.

14 changes: 0 additions & 14 deletions Functional/DropWhile.ark

This file was deleted.

8 changes: 0 additions & 8 deletions Functional/Either.ark

This file was deleted.

8 changes: 0 additions & 8 deletions Functional/Exceptions.ark

This file was deleted.

11 changes: 0 additions & 11 deletions Functional/Filter.ark

This file was deleted.

2 changes: 0 additions & 2 deletions Functional/Flip.ark

This file was deleted.

14 changes: 0 additions & 14 deletions Functional/Functional.ark

This file was deleted.

9 changes: 0 additions & 9 deletions Functional/Map.ark

This file was deleted.

9 changes: 0 additions & 9 deletions Functional/Reduce.ark

This file was deleted.

9 changes: 0 additions & 9 deletions Functional/Take.ark

This file was deleted.

15 changes: 0 additions & 15 deletions Functional/TakeWhile.ark

This file was deleted.

13 changes: 0 additions & 13 deletions Functional/Unzip.ark

This file was deleted.

14 changes: 0 additions & 14 deletions Functional/Zip.ark

This file was deleted.

Loading