diff options
author | Louis Pilfold <louis@lpil.uk> | 2023-08-03 12:23:39 +0100 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2023-08-03 12:23:39 +0100 |
commit | ceda2e3813cb5e8be7304b518e589c538b810d9e (patch) | |
tree | 41c510f8df25e714ab1e607410d127bc108eed26 /src | |
parent | 30569cb26334d0e253c66dfa7cb92c18ba0f3d8d (diff) | |
download | javascript-ceda2e3813cb5e8be7304b518e589c538b810d9e.tar.gz javascript-ceda2e3813cb5e8be7304b518e589c538b810d9e.zip |
Update for Gleam v0.30
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/javascript.gleam | 24 | ||||
-rw-r--r-- | src/gleam/javascript/array.gleam | 34 | ||||
-rw-r--r-- | src/gleam/javascript/promise.gleam | 100 |
3 files changed, 81 insertions, 77 deletions
diff --git a/src/gleam/javascript.gleam b/src/gleam/javascript.gleam index c7efddb..a0c12ba 100644 --- a/src/gleam/javascript.gleam +++ b/src/gleam/javascript.gleam @@ -10,24 +10,24 @@ pub type TypeOf { FunctionType } -pub external type Symbol +pub type Symbol -pub external fn type_of(value) -> TypeOf = - "../ffi.mjs" "type_of" +@external(javascript, "../ffi.mjs", "type_of") +pub fn type_of(a: value) -> TypeOf -pub external fn get_symbol(String) -> Symbol = - "../ffi.mjs" "get_symbol" +@external(javascript, "../ffi.mjs", "get_symbol") +pub fn get_symbol(a: String) -> Symbol -pub external type Reference(value) +pub type Reference(value) -pub external fn dereference(Reference(a)) -> a = - "../ffi.mjs" "dereference" +@external(javascript, "../ffi.mjs", "dereference") +pub fn dereference(a: Reference(a)) -> a -pub external fn set_reference(Reference(a), a) -> a = - "../ffi.mjs" "set_reference" +@external(javascript, "../ffi.mjs", "set_reference") +pub fn set_reference(a: Reference(a), b: a) -> a -pub external fn make_reference(a) -> Reference(a) = - "../ffi.mjs" "make_reference" +@external(javascript, "../ffi.mjs", "make_reference") +pub fn make_reference(a: a) -> Reference(a) // returns the old value pub fn update_reference(ref: Reference(a), f: fn(a) -> a) -> a { diff --git a/src/gleam/javascript/array.gleam b/src/gleam/javascript/array.gleam index 19b860d..e644236 100644 --- a/src/gleam/javascript/array.gleam +++ b/src/gleam/javascript/array.gleam @@ -2,28 +2,28 @@ /// /// Unlike most data structures in Gleam this one is mutable. /// -pub external type Array(element) +pub type Array(element) /// Convert a JavaScript array to a Gleam list. /// /// Runs in linear time. /// -pub external fn to_list(Array(element)) -> List(element) = - "../../gleam.mjs" "toList" +@external(javascript, "../../gleam.mjs", "toList") +pub fn to_list(a: Array(element)) -> List(element) /// Convert a Gleam list to a JavaScript array. /// /// Runs in linear time. /// -pub external fn from_list(List(element)) -> Array(element) = - "../../ffi.mjs" "toArray" +@external(javascript, "../../ffi.mjs", "toArray") +pub fn from_list(a: List(element)) -> Array(element) /// Get the number of elements in the array. /// /// Runs in constant time. /// -pub external fn size(Array(element)) -> Int = - "../../ffi.mjs" "length" +@external(javascript, "../../ffi.mjs", "length") +pub fn size(a: Array(element)) -> Int /// Returns a new array containing only the elements of the first array after /// the function has been applied to each one. @@ -37,8 +37,8 @@ pub external fn size(Array(element)) -> Int = /// from_list([4, 8, 12]) /// ``` /// -pub external fn map(Array(a), with: fn(a) -> b) -> Array(b) = - "../../ffi.mjs" "map" +@external(javascript, "../../ffi.mjs", "map") +pub fn map(a: Array(a), with with: fn(a) -> b) -> Array(b) /// Reduces a list of elements into a single value by calling a given function /// on each element, going from left to right. @@ -48,8 +48,8 @@ pub external fn map(Array(a), with: fn(a) -> b) -> Array(b) = /// /// Runs in linear time. /// -pub external fn fold(over: Array(e), from: a, with: fn(a, e) -> a) -> a = - "../../ffi.mjs" "reduce" +@external(javascript, "../../ffi.mjs", "reduce") +pub fn fold(over over: Array(e), from from: a, with with: fn(a, e) -> a) -> a /// Reduces a list of elements into a single value by calling a given function /// on each element, going from right to left. @@ -59,8 +59,12 @@ pub external fn fold(over: Array(e), from: a, with: fn(a, e) -> a) -> a = /// /// Runs in linear time. /// -pub external fn fold_right(over: Array(e), from: a, with: fn(a, e) -> a) -> a = - "../../ffi.mjs" "reduceRight" +@external(javascript, "../../ffi.mjs", "reduceRight") +pub fn fold_right( + over over: Array(e), + from from: a, + with with: fn(a, e) -> a, +) -> a /// Get the element at the given index. /// @@ -76,5 +80,5 @@ pub external fn fold_right(over: Array(e), from: a, with: fn(a, e) -> a) -> a = /// Error(Nil) /// ``` /// -pub external fn get(Array(e), Int) -> Result(e, Nil) = - "../../ffi.mjs" "index" +@external(javascript, "../../ffi.mjs", "index") +pub fn get(a: Array(e), b: Int) -> Result(e, Nil) diff --git a/src/gleam/javascript/promise.gleam b/src/gleam/javascript/promise.gleam index 94559ac..8d531eb 100644 --- a/src/gleam/javascript/promise.gleam +++ b/src/gleam/javascript/promise.gleam @@ -3,19 +3,19 @@ import gleam/javascript/array.{Array} // TODO: docs // TODO: labels -pub external type Promise(value) +pub type Promise(value) -pub external fn resolve(value) -> Promise(value) = - "../../ffi.mjs" "resolve" +@external(javascript, "../../ffi.mjs", "resolve") +pub fn resolve(a: value) -> Promise(value) -pub external fn rescue(Promise(value), fn(Dynamic) -> value) -> Promise(value) = - "../../ffi.mjs" "rescue" +@external(javascript, "../../ffi.mjs", "rescue") +pub fn rescue(a: Promise(value), b: fn(Dynamic) -> value) -> Promise(value) -pub external fn await(Promise(a), fn(a) -> Promise(b)) -> Promise(b) = - "../../ffi.mjs" "then" +@external(javascript, "../../ffi.mjs", "then") +pub fn await(a: Promise(a), b: fn(a) -> Promise(b)) -> Promise(b) -pub external fn map(Promise(a), fn(a) -> b) -> Promise(b) = - "../../ffi.mjs" "map_promise" +@external(javascript, "../../ffi.mjs", "map_promise") +pub fn map(a: Promise(a), b: fn(a) -> b) -> Promise(b) pub fn tap(promise: Promise(a), callback: fn(a) -> b) -> Promise(a) { promise @@ -51,45 +51,45 @@ pub fn try_await( }) } -pub external fn await2(Promise(a), Promise(b)) -> Promise(#(a, b)) = - "../../ffi.mjs" "all_promises" - -pub external fn await3( - Promise(a), - Promise(b), - Promise(c), -) -> Promise(#(a, b, c)) = - "../../ffi.mjs" "all_promises" - -pub external fn await4( - Promise(a), - Promise(b), - Promise(c), - Promise(d), -) -> Promise(#(a, b, c, d)) = - "../../ffi.mjs" "all_promises" - -pub external fn await5( - Promise(a), - Promise(b), - Promise(c), - Promise(d), - Promise(e), -) -> Promise(#(a, b, c, d, e)) = - "../../ffi.mjs" "all_promises" - -pub external fn await6( - Promise(a), - Promise(b), - Promise(c), - Promise(d), - Promise(e), - Promise(f), -) -> Promise(#(a, b, c, d, e, f)) = - "../../ffi.mjs" "all_promises" - -pub external fn await_array(Array(Promise(a))) -> Promise(Array(a)) = - "../../ffi.mjs" "all_promises" +@external(javascript, "../../ffi.mjs", "all_promises") +pub fn await2(a: Promise(a), b: Promise(b)) -> Promise(#(a, b)) + +@external(javascript, "../../ffi.mjs", "all_promises") +pub fn await3( + a: Promise(a), + b: Promise(b), + c: Promise(c), +) -> Promise(#(a, b, c)) + +@external(javascript, "../../ffi.mjs", "all_promises") +pub fn await4( + a: Promise(a), + b: Promise(b), + c: Promise(c), + d: Promise(d), +) -> Promise(#(a, b, c, d)) + +@external(javascript, "../../ffi.mjs", "all_promises") +pub fn await5( + a: Promise(a), + b: Promise(b), + c: Promise(c), + d: Promise(d), + e: Promise(e), +) -> Promise(#(a, b, c, d, e)) + +@external(javascript, "../../ffi.mjs", "all_promises") +pub fn await6( + a: Promise(a), + b: Promise(b), + c: Promise(c), + d: Promise(d), + e: Promise(e), + f: Promise(f), +) -> Promise(#(a, b, c, d, e, f)) + +@external(javascript, "../../ffi.mjs", "all_promises") +pub fn await_array(a: Array(Promise(a))) -> Promise(Array(a)) pub fn await_list(xs: List(Promise(a))) -> Promise(List(a)) { xs @@ -97,5 +97,5 @@ pub fn await_list(xs: List(Promise(a))) -> Promise(List(a)) { |> map(array.to_list) } -external fn do_await_list(List(Promise(a))) -> Promise(Array(a)) = - "../../ffi.mjs" "all_promises" +@external(javascript, "../../ffi.mjs", "all_promises") +fn do_await_list(a: List(Promise(a))) -> Promise(Array(a)) |