trying to work around a problem in outside library - is there a way to try-catch the generator itself item by item (probably not, but just to be sure...)?
let myTest() =
let mySeq = seq { for i in -3 .. 3 -> 1 / i }
// how to keep the line above intact, but modify the code below to try-catch-ignore the bad one?
mySeq |> Seq.iter (fun i -> printfn "%d" i)
()
Given a linear function f(x) = mx + b, The vertical intercept (y-intercept) is found by evaluating the function when the input variable, x, is 0 and is always the same as the constant b. It can be thought of as the original value of the function.
Intercepts are those points on a Cartesian coordinate system where the graph of an equation or function crosses the x- and y-axes. To find the x-intercept algebraically, simply set y to 0 and solve for x. Conversely, to find the y-intercept, set the value of x to 0 and solve for y.
To find the y-intercept of a function, we need to find the point on the graph where x = 0. Given a function, f(x), the y-intercept occurs at f(0). Thus, the y-intercept is at (0, -4).
The y-intercept formula says that the y-intercept of a function y = f(x) is obtained by substituting x = 0 in it. Using this, the y-intercept of a graph is the point on the graph whose x-coordinate is 0. i.e., just look for the point where the graph intersects the y-axis and it is the y-intercept.
You can't.
Once the exception happens, the state of the source enumerator is screwed up. If you can't get into the source enumerator to "fix" its state, you can't make it keep producing values.
You can, however, make the whole process "stop" after the exception, but you'll have to go a level below and work with IEnumerator<T>
:
let takeUntilError (sq: seq<_>) = seq {
use enm = sq.GetEnumerator()
let next () = try enm.MoveNext() with _ -> false
let cur () = try Some enm.Current with _ -> None
while next() do
match cur() with
| Some c -> yield c
| None -> ()
}
mySeq |> takeUntilError |> Seq.iter (printf "%d")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With