aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2022-01-01 22:24:16 +0000
committerLouis Pilfold <louis@lpil.uk>2022-01-01 22:24:16 +0000
commit08606b3dd9d4928c33da4f1eba6000626f41627d (patch)
tree665c2c68c6182b5f99b5a39176194cf9bd2303b9 /src
parentbb4e842a641077fafb102bb104492b50b85cd50a (diff)
downloadgleam_stdlib-08606b3dd9d4928c33da4f1eba6000626f41627d.tar.gz
gleam_stdlib-08606b3dd9d4928c33da4f1eba6000626f41627d.zip
Element requires type
Diffstat (limited to 'src')
-rw-r--r--src/gleam/dynamic.gleam8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/gleam/dynamic.gleam b/src/gleam/dynamic.gleam
index fa1b69e..82cfa2f 100644
--- a/src/gleam/dynamic.gleam
+++ b/src/gleam/dynamic.gleam
@@ -421,11 +421,12 @@ if javascript {
///
pub fn element(
from data: Dynamic,
- get index: Int,
-) -> Result(Dynamic, DecodeError) {
+ at index: Int,
+ of inner_type: Decoder(t),
+) -> Result(t, DecodeError) {
try tuple = decode_tuple(data)
let size = tuple_size(tuple)
- case index >= 0 {
+ try data = case index >= 0 {
True ->
case index < size {
True -> tuple_get(tuple, index)
@@ -437,6 +438,7 @@ pub fn element(
False -> at_least_decode_tuple_error(int.absolute_value(index), data)
}
}
+ inner_type(data)
}
fn exact_decode_tuple_error(size: Int, data: Dynamic) -> Result(a, DecodeError) {