Question: Is there some way I can have a function whose return type varies based on one of its arguments? For example:

```
interface Person {
  name: string;
  job: string;
}

interface Animal {
  name: string;
  deadly: boolean;
}

function getPerson(): Person {
  return {
    name: 'Bob',
    job: 'Manager',
  };
}

function getAnimal(): Animal {
  return {
    name: 'Spot',
    deadly: false,
  };
}

function create(generator: () => Person | Animal): ReturnType<typeof generator>[] {
  return []
}

const people = create(getPerson);

```

This is kind of close, except the type of `people` is `(Person | Animal)[]`. I need it to be `Person[]` - in other words, it can look at the `getPerson` argument and know that this function will return a `Person`. I realize, of course, I could rewrite the function so I can do this:

```
const people = create<Person>(getPerson);

```

But I'd rather have it infer this from the arguments somehow.

Answer: 
You have have multiple `=` in a single match.

```
%{"name" => name} = identity = RedditOAuth2.get_identity(access_token)

```

`identity` will have the entire map assigned to it and `name` will have whatever was in the `"name"` key.
If you're wanting to discard everything else from the identity and are okay adding another function, you may be looking for [`Map.split/2`](https://hexdocs.pm/elixir/Map.html#split/2).

```rb
{%{"name" => name}, identity} =
  access_token
  |> RedditOAuth2.get_identity()
  |> Map.split(["name"])

```