bcpeinhardt / simplifile

Simple file operations for Gleam that work on all targets (Erlang/Node/Deno)
71 stars 10 forks source link

Remove unneeded conditional compilation #5

Closed lpil closed 1 year ago

lpil commented 1 year ago

Hello!

It seems there's code like this in this library:

/// hello!
pub fn thing() -> X {
  do_thing()
}

@target(erlang)
@external(erlang, "a", "b")
fn do_thing() -> X

@target(javascript)
@external(javascript, "a.mjs", "b")
fn do_thing() -> X

This can be written more concisely like so, and it'll also remove the extra function call

/// hello!
@external(erlang, "a", "b")
@external(javascript, "a.mjs", "b")
pub fn thing() -> X

Is there a reason you want to have the conditional compilation?

bcpeinhardt commented 1 year ago

If you look at the function signatures, they actually have slightly different return types. I'm stringifying the error in JavaScript and converting it to the correct type in Gleam, because I wasn't sure how to turn it into a correct runtime representation in the JavaScript.

I do want to consolidate this code, just haven't gone through the trouble of figuring it out quite yet :)

lpil commented 1 year ago

Ah I see! My bad. Thank you