# Need an example extending existing libraries

**URL:** <https://discourse.elm-lang.org/t/need-an-example-extending-existing-libraries/5437>\
**Category:** Learn\
**Created:** [April 4, 2020, 7:26pm UTC](https://discourse.elm-lang.org/t/need-an-example-extending-existing-libraries/5437 "2020-04-04T19:26:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edward\_Bond](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/edward_bond/32/3101_2.png) [@Edward\_Bond](https://discourse.elm-lang.org/u/Edward_Bond)\
**Post date:** [April 4, 2020, 7:26pm UTC](https://discourse.elm-lang.org/t/need-an-example-extending-existing-libraries/5437/1 "2020-04-04T19:26:48Z")

</div>

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:

```auto
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](https://github.com/the-sett/elm-aws-core/blob/4.0.0/src/AWS/Core/Service.elm)

They have a function that looks like:

```auto
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

---

<div class="post-metadata">

**Author:** ![passiomatic](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/passiomatic/32/1250_2.png) [@passiomatic](https://discourse.elm-lang.org/u/passiomatic)\
**Post date:** [April 4, 2020, 8:48pm UTC](https://discourse.elm-lang.org/t/need-an-example-extending-existing-libraries/5437/2 "2020-04-04T20:48:41Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![Edward\_Bond](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/edward_bond/32/3101_2.png) [@Edward\_Bond](https://discourse.elm-lang.org/u/Edward_Bond)\
**Post date:** [April 4, 2020, 10:00pm UTC](https://discourse.elm-lang.org/t/need-an-example-extending-existing-libraries/5437/3 "2020-04-04T22:00:44Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![rupert](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/rupert/32/1775_2.png) [@rupert](https://discourse.elm-lang.org/u/rupert)\
**Post date:** [April 4, 2020, 10:06pm UTC](https://discourse.elm-lang.org/t/need-an-example-extending-existing-libraries/5437/4 "2020-04-04T22:06:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Edward\_Bond](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/edward_bond/32/3101_2.png) [@Edward\_Bond](https://discourse.elm-lang.org/u/Edward_Bond)\
**Post date:** [April 4, 2020, 10:12pm UTC](https://discourse.elm-lang.org/t/need-an-example-extending-existing-libraries/5437/5 "2020-04-04T22:12:51Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [April 14, 2020, 10:12pm UTC](https://discourse.elm-lang.org/t/need-an-example-extending-existing-libraries/5437/6 "2020-04-14T22:12:54Z")

</div>

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