Need an example extending existing libraries

Hello!

Just getting into elm and I have been going through a couple books/online tutorials.

Problem:

I am trying to understand how to extend existing libraries. Inside my own code base.

In elixir it I would like to be able to do something like:

def update_video_name(video) do
  video |> Map.merge(%{name: "def"})
end
x = %Video{url: "https://asdf.com/a.m3u8", name: "abc"}
y = update_video_name(video)

Where Video is a struct from another library.

Elm example

AWS.Core.Service

They have a function that looks like:

setTargetPrefix : String -> Service -> Service
setTargetPrefix prefix (Service service) =
    Service { service | targetPrefix = prefix }

When I try to do that in my own elm I am getting an error on the:
Service on like 3 saying that it can’t find the variant

Summary

I can’t find a way to mutate private data structures to tweak values without doing either a fork or waiting for a PR to get merged.

If I am thinking about this all wrong please help!

thanks in advance

Hi. As you might already have guessed this is likely to be done on purpose by the package author since if you look at line 2 here: https://github.com/the-sett/elm-aws-core/blob/4.0.0/src/AWS/Core/Service.elm#L2 you can see the single variant of the Service type is not exposed, otherwise you would see Service(..).

Of course you can always open an issue on Github or trying to elaborate here why you need to change the type inner data structures.

Gotcha.

So this is a pattern of elm to close the translations of data in a non exposed pattern?

I dont mind doing a PR or fixing whatever. Just trying to learn the system more.

Thanks!

Are you needing to change a field of Service? If there is something missing from the API you need, I am sure it can be added. I took over this codebase from the original work by Kevin Tonon - so it can be a little untidy due to the change of hands - but lets fix it.

@rupert

Haha, I got it figured out.

Long story short, I used your library to figure out how to do a signing against an appsync backend.

The crux comes in where the signing application needs to be appsync but the host url portion is different because of the api endpoint.

The next part is to figure out between elm-graphql and your library which would be the best way to extend it.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.