diff options
author | Louis Pilfold <louis@lpil.uk> | 2018-12-01 23:47:45 +0000 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2018-12-01 23:47:45 +0000 |
commit | 466eda4accdaa2e70b4f16a5dc885dcb23d8dac5 (patch) | |
tree | 5e94c80d04d7257359706d8fc683576792cc0747 /src | |
parent | fd7dc023cbb512d51c5ac7a45271d1625fa945af (diff) | |
download | gleam_stdlib-466eda4accdaa2e70b4f16a5dc885dcb23d8dac5.tar.gz gleam_stdlib-466eda4accdaa2e70b4f16a5dc885dcb23d8dac5.zip |
iodata
Diffstat (limited to 'src')
-rw-r--r-- | src/any.gleam | 8 | ||||
-rw-r--r-- | src/gleam__stdlib.erl | 7 | ||||
-rw-r--r-- | src/iodata.gleam | 23 |
3 files changed, 31 insertions, 7 deletions
diff --git a/src/any.gleam b/src/any.gleam index 772078b..30c6cf4 100644 --- a/src/any.gleam +++ b/src/any.gleam @@ -8,7 +8,7 @@ pub external type Any; // doc """ // Convert any Gleam data into `Any` data. // """ -pub external fn from(a) -> Any = 'gleam_any' 'identity'; +pub external fn from(a) -> Any = 'gleam__stdlib' 'identity'; // doc """ // Unsafely cast any type into any other type.o @@ -16,8 +16,4 @@ pub external fn from(a) -> Any = 'gleam_any' 'identity'; // This is an escape hatch for the type system that may be useful when wrapping // native Erlang APIs. It is to be used as a last measure only. // """ -pub external fn unsafeCoerce(a) -> b = 'gleam_any' 'identity'; - -pub fn identity(x) { - x -} +pub external fn unsafeCoerce(a) -> b = 'gleam__stdlib' 'identity'; diff --git a/src/gleam__stdlib.erl b/src/gleam__stdlib.erl index 5942a0f..e4b76f7 100644 --- a/src/gleam__stdlib.erl +++ b/src/gleam__stdlib.erl @@ -10,5 +10,10 @@ expect_false(A) -> ?assertNot(A). map_fetch(Map, Key) -> case maps:find(Key, Map) of error -> {error, {}}, - Found -> Found + OkFound -> OkFound end. + +iodata_append(X, Data) -> [X | Y]. +iodata_prepend(X, Data) -> [Y, X]. + +identity(X) -> X. diff --git a/src/iodata.gleam b/src/iodata.gleam new file mode 100644 index 0000000..285a99d --- /dev/null +++ b/src/iodata.gleam @@ -0,0 +1,23 @@ +import any + +// TODO: Tests + +pub external type Iodata; + +pub external fn prepend(Iodata, String) -> Iodata = + 'gleam__stdlib' 'iodata_prepend'; + +pub external fn append(Iodata, String) -> Iodata = + 'gleam__stdlib' 'iodata_append'; + +pub external fn of(String) -> Iodata = + 'gleam__stdlib' 'identity'; + +pub external fn from(List(String)) -> Iodata = + 'gleam__stdlib' 'identity'; + +pub external fn to_string(Iodata) -> String = + 'erlang' 'iolist_to_binary'; + +pub external fn byte_size(Iodata) -> Int = + 'erlang' 'iolist_size'; |