All function
Warning
This documentation refers to the Classic QDK, which has been replaced by the Modern QDK.
Please see https://aka.ms/qdk.api for the API documentation for the Modern QDK.
Namespace: Microsoft.Quantum.Arrays
Package: 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.
function All<'T> (predicate : ('T -> Bool), array : 'T[]) : Bool
Input
predicate : 'T -> Bool
A function from 'T
to Bool
that is used to check elements.
array : 'T[]
An array of elements over 'T
.
Output : 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:
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
.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for