Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Conversation

@cgranade
Copy link
Contributor

@cgranade cgranade commented Nov 23, 2020

This PR exposes examples from doc comments as a section per each example. Should fix MicrosoftDocs/quantum-docs-pr#1121. Marked as draft until an e2e build can verify correct documentation output.

Please see build at https://dev.azure.com/ms-quantum-public/Microsoft%20Quantum%20(public)/_build/results?buildId=19347&view=results for documentation built from this PR.

@cgranade
Copy link
Contributor Author

It looks like it works (example below), so moving this out of draft.

---
uid: Microsoft.Quantum.Arrays.All
title: All function
ms.date: 11/23/2020 12:00:00 AM
ms.topic: article
qsharp.kind: function
qsharp.namespace: Microsoft.Quantum.Arrays
qsharp.name: All
qsharp.summary: >-
  Given an array and a predicate that is defined
  for the elements of the array, and checks if all elements of the
  array satisfy the predicate.
---

# All function

Namespace: [Microsoft.Quantum.Arrays](xref:Microsoft.Quantum.Arrays)

Package: [Microsoft.Quantum.Standard](https://nuget.org/packages/Microsoft.Quantum.Standard)


Given an array and a predicate that is defined
for the elements of the array, and checks if all elements of the
array satisfy the predicate.

```qsharp
function All<'T> (predicate : ('T -> Bool), array : 'T[]) : Bool
```


## Input

### predicate : 'T -> [Bool](xref:microsoft.quantum.lang-ref.bool)

A function from `'T` to `Bool` that is used to check elements.


### array : 'T[]

An array of elements over `'T`.



## Output : [Bool](xref:microsoft.quantum.lang-ref.bool)

A `Bool` value of the AND function of the predicate applied to all elements.

## Type Parameters

### 'T

The type of `array` elements.

## Example

The following code checks whether all elements of the array are non-zero:

```qsharp
open Microsoft.Quantum.Arrays;
open Microsoft.Quantum.Logical;

function AllDemo() : Unit {
    let predicate = NotEqualI(_, 0);
    let isNonZero = All(predicate, [2, 3, 4, 5, 6, 0]);
    Message($"{isNonZero}");
}
```

## Remarks

The function is defined for generic types, i.e., whenever we have
an array `'T[]` and a function `predicate: 'T -> Bool` we can produce
a `Bool` value that indicates if all elements satisfy `predicate`.

@cgranade cgranade marked this pull request as ready for review November 23, 2020 21:26
@geduardo
Copy link

geduardo commented Jan 6, 2021

Can we merge this @cgranade?

@bamarsha
Copy link
Contributor

bamarsha commented Jan 7, 2021

@cgranade I think the PR build should be fixed by #806 if you merge main into this branch now.

@github-actions github-actions bot merged commit 97d70cd into main Jan 7, 2021
@cgranade cgranade deleted the cgranade/doc-examples branch January 7, 2021 21:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Examples from Q# Libraries API don't show up in docs

5 participants