@@ -153,55 +153,4 @@ struct ResultOk2{A<:AbstractArray,B<:AbstractArray}
153153 ok:: Bool
154154end
155155
156- # ! format: on
157- """
158- nif(condition, expression, [else_expression,] ::Val{N}) where {N}
159-
160- Generate a sequence of `if ... elseif ... else ... end` statements.
161- This is copied from https://github.com/JuliaLang/julia/pull/55093.
162-
163- # Arguments
164- - `condition`: A function that takes an integer between `1` and `N-1` and
165- returns a boolean condition.
166- - `expression`: A function that takes an integer between `1` and `N` (or,
167- only up to `N-1`, if `else_expression` is provided) and is called if
168- the condition is true.
169- - `else_expression`: (optional) A function that takes `N` as input
170- returns an expression to be evaluated if all conditions are false.
171- - `N`: The number of conditions to check, passed as a `Val{N}` instance.
172- This function is similar to the `@nif` macro but can be used in cases
173- where `N` is not known at parse time.
174- # Examples
175- For example, here we find the first index of a positive element in a
176- fixed-size tuple using `nif`:
177- ```jldoctest
178- julia> x = (0, -1, 1, 0)
179- (0, -1, 1, 0)
180- julia> Base.Cartesian.nif(d -> x[d] > 0, d -> d, Val(4))
181- 3
182- ```
183- """
184- @inline function nif (condition:: F , expression:: G , :: Val{N} ) where {F,G,N}
185- return nif (condition, expression, expression, Val (N))
186- end
187- @inline function nif (
188- condition:: F , expression:: G , else_expression:: H , :: Val{N}
189- ) where {F,G,H,N}
190- n = N:: Int # Can improve inference; see #54544
191- (n >= 0 ) || throw (ArgumentError (" if statement length should be ≥ 0, got $n " ))
192- if @generated
193- :(Base. Cartesian. @nif $ N d -> condition (d) d -> expression (d) d ->
194- else_expression (d))
195- else
196- for d in 1 : (n - 1 )
197- if condition (d)
198- return expression (d)
199- end
200- end
201- return else_expression (n)
202- end
203- end
204- typeof (function nif end ). name. max_methods = UInt8 (2 )
205- # ! format: off
206-
207156end
0 commit comments