From d7cf6c9a27487b182c1e6d832a58e01d022b97fa Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Sun, 29 Aug 2021 15:28:05 +0100 Subject: Array index --- src/ffi.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/ffi.js') diff --git a/src/ffi.js b/src/ffi.js index 81362bb..c0b2076 100644 --- a/src/ffi.js +++ b/src/ffi.js @@ -1,3 +1,5 @@ +import { Ok, Error } from "./gleam.js"; + export function toArray(list) { return list.toArray(); } @@ -17,3 +19,7 @@ export function reduce(thing, acc, fn) { export function reduceRight(thing, acc, fn) { return thing.reduceRight(fn, acc); } + +export function index(thing, index) { + return index in thing ? new Ok(thing[index]) : new Error(undefined); +} -- cgit v1.2.3