# What is a 'λ-Scoped(x, scope={})'

**URL:** <https://community.riskscape.org.nz/t/what-is-a-scoped-x-scope/193>\
**Category:** Community\
**Created:** [2 October 2024 01:30 UTC](https://community.riskscape.org.nz/t/what-is-a-scoped-x-scope/193 "2024-10-02T01:30:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JPowell](https://avatars.discourse-cdn.com/v4/letter/j/bbce88/32.png) [@JPowell](https://community.riskscape.org.nz/u/JPowell)\
**Post date:** [2 October 2024 01:30 UTC](https://community.riskscape.org.nz/t/what-is-a-scoped-x-scope/193/1 "2024-10-02T01:30:23Z")

</div>

When trying to run the pipeline below

```auto
input(relation: 'testcsv', name: 'exposure')
->
select({
	create_continuous(
	[0.0,0.1,0.2],
	[0,500,1000]) as testCurve
})
->
select({apply_continuous(testCurve, [250,750])})

```

I am getting the error

```auto
Failed to validate model for execution
  - Failed to validate 'select({create_continuous([0.0, 0.1, 0.2], [0, 500, 1000]) as testCurve})' step for execution
    - Failed to validate expression '{create_continuous([0.0, 0.1, 0.2], [0, 500, 1000]) as testCurve}' against input type {exposure=>{}}
      - Problems found with 'create_continuous' riskscape function
        - Type mismatch for apply-to. Expected 'λ-Scoped(x, scope={})' but found 'List[Integer]'

```

What is a ‘λ-Scoped(x, scope={})’ and how can I use apply\_continuous on a list?

My expected output was  
0.05  
0.15

---

<div class="post-metadata">

**Author:** ![timbeale](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@timbeale](https://community.riskscape.org.nz/u/timbeale)\
**Post date:** [2 October 2024 02:09 UTC](https://community.riskscape.org.nz/t/what-is-a-scoped-x-scope/193/2 "2024-10-02T02:09:40Z")

</div>

Kia ora,

That’s a scoped lambda type. There’s an explanation in the docs about what RiskScape lambda expressions are here:  
[https://riskscape.org.nz/docs/intermediate/write-expressions.html#lambda-expressions](https://riskscape.org.nz/docs/intermediate/write-expressions.html#lambda-expressions)

The ‘scoped’ part just means the lambda expression can access any other attributes that are accessible for that particular pipeline step (e.g. exposure attributes).

The `create_continuous()` function expects a lambda expression that will yield a `y` value for a given `x` value. (Replace x and y with domain-appropriate modelling terminology, e.g. x=flood depth, y=DR). For example, a simple example of a lambda expression might be: `x -> if(x > 500, then: 0.2, else: 0.1)`.

This is not exactly what you want here. What you want is more like ‘given a predetermined x value, return a predetermined y value’. The simplest way to do this in a pipeline is via a ‘lookup table’. Here’s an example:

```auto
input(value: { x_point: [0.0,500.0,1000.0], y_point: [0.0,0.1,0.2] })
->
unnest([x_point, y_point]) as foo
->
group({ to_lookup_table(key: x_point, value: y_point, options: { unique: true }) as lookup_table })
->
select({
	create_continuous(
	[0.0,500.0,1000.0],
	x -> lookup(lookup_table, x)) as testCurve
})
->
select({
        apply_continuous(testCurve, 250) as y250,
        apply_continuous(testCurve, 750) as y750
})

```

Hope that helps.

Tim

---

<div class="post-metadata">

**Author:** ![JPowell](https://avatars.discourse-cdn.com/v4/letter/j/bbce88/32.png) [@JPowell](https://community.riskscape.org.nz/u/JPowell)\
**Post date:** [7 October 2024 22:39 UTC](https://community.riskscape.org.nz/t/what-is-a-scoped-x-scope/193/3 "2024-10-07T22:39:22Z")

</div>

Thanks Tim that is working well.

Is there a way I can reuse the key from the lookup table when we create the curve? I tried

```auto
select({
	create_continuous(
	lookup_table.key,
	x -> lookup(lookup_table, x)) as testCurve
})

```

as well as foo.x\_point

but neither are working

---

<div class="post-metadata">

**Author:** ![timbeale](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@timbeale](https://community.riskscape.org.nz/u/timbeale)\
**Post date:** [7 October 2024 23:42 UTC](https://community.riskscape.org.nz/t/what-is-a-scoped-x-scope/193/4 "2024-10-07T23:42:05Z")

</div>

Probably the simplest way is to use a model parameter for the x points in the curve, e.g.

```auto
input(value: { x_point: $interpolation_points, y_point: [0.0,0.1,0.2] })
->
unnest([x_point, y_point]) as foo
->
group({ to_lookup_table(key: x_point, value: y_point, options: { unique: true }) as lookup_table })
->
select({
	create_continuous(
  	  $interpolation_points,
	  x -> lookup(lookup_table, x)) as testCurve
})
->
select({
        apply_continuous(testCurve, 250) as y250,
        apply_continuous(testCurve, 750) as y750
})

```

That assume you’re running this as a model (rather than using the `riskscape pipeline evaluate` command). E.g.

```auto
[model example_curve]
framework = pipeline
location = foo.txt
param.interpolation_points = [0.0,500.0,1000.0]

```

Hope that helps.
