Skip to content

Commit

Permalink
Merge pull request #1 from johnlokerse/johnlokerse/add-udf
Browse files Browse the repository at this point in the history
Added UDF cheatsheet
  • Loading branch information
johnlokerse authored May 29, 2024
2 parents 7a47f44 + 29e4278 commit 9861408
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,52 @@ param parCustomArray arrayWithObjectsType = [

</details>

<details>
<summary>
<span><b>User Defined Functions</b></span>
<p><i>Define custom complex expressions.</i></p>
</summary>

### User-defined function syntax

```func <function-name> (<parameter-name> <data-type>) <return-type> => <expression>```

### Basic user-defined function

```bicep
func funcSayHelloTo() string => 'Hello and welcome, John Doe'
```

### User-defined function with parameters

```bicep
func funcSayHelloTo(name string) string => 'Hello and welcome, ${name}'
```

With multiple parameters:

```bicep
func funcPersonNameAndAge(name string, age int) string => 'My name is ${name} and my age is ${age}'
```

### User-defined function return types

```bicep
func funcReturnTypeArray() array => [1, 2, 3, 4, 5]
func funcReturnTypeObject() object => {name: 'John Doe', age: 31}
func funcReturnTypeInt() int => 1337
func funcReturnTypeBool(key string) bool => contains({}, key)
func funcReturnTypeUserDefinedType() customTypeUsedAsReturnType => {
hello: 'world'
}
type customTypeUsedAsReturnType = {
hello: string
}
```

</details>

<details>
<summary>
<span><b>Compile-time imports</b></span>
Expand Down

0 comments on commit 9861408

Please sign in to comment.