control-flow

Design issue: to what extent should I rely on exceptions for the flow of control?

核能气质少年 提交于 2019-12-06 04:56:57
I am working on a java web application and I have a few questions regarding design. Basically in its current version, it relies heavily on catching exceptions to determine the flow of control . For instance in one of my spring service classes, I have the following method that checks whether an email given as a parameter exists in the database. @Override public boolean validateEmailAddressDoesNotExist(String accountEmailAddress) { try { return !dao.checkIfEmailAddressAlreadyExists(accountEmailAddress); } catch (NoResultException re) { log.error("NoResultException", re); } catch

How can I stop a package execution based on a stored procedure output?

假装没事ソ 提交于 2019-12-05 10:40:26
I have an SSIS package that the first task executes a stored procedure to verify that the run date is not a holiday. If it is a holiday, then it returns a record set with a count of 1. I want to be able to stop the SSIS if the recordcount is 1 but continue to run if the recordcount is zero. I don't know the best way to implement this. What control flow item should I add to the package? I am relatively new to SSIS so I don't know what item to add. Any help would be great. Well one way is to create an Execute SQl task to use that you use to set the value of variable @Holiday. Then change the

asyncio as_yielded from async generators

Deadly 提交于 2019-12-05 03:43:59
I'm looking to be able to yield from a number of async coroutines. Asyncio's as_completed is kind of close to what I'm looking for (i.e. I want any of the coroutines to be able to yield at any time back to the caller and then continue), but that only seems to allow regular coroutines with a single return. Here's what I have so far: import asyncio async def test(id_): print(f'{id_} sleeping') await asyncio.sleep(id_) return id_ async def test_gen(id_): count = 0 while True: print(f'{id_} sleeping') await asyncio.sleep(id_) yield id_ count += 1 if count > 5: return async def main(): runs = [test

what is the control flow of django rest framework

℡╲_俬逩灬. 提交于 2019-12-04 23:20:34
问题 I am developing an api for a webapp. I was initially using tastypie and switched to django-rest-framework (drf) . Drf seems very easy to me. What I intend to do is to create nested user profile object. My models are as below from django.db import models from django.contrib.auth.models import User class nestedmodel(models.Model): info = models.CharField(null=True, blank=True, max_length=100) class UserProfile(models.Model): add_info = models.CharField(null=True, blank=True, max_length=100)

How to implement a more general reduce function to allow early exit?

故事扮演 提交于 2019-12-04 13:59:43
问题 reduce (aka foldL in FP) is the most general iterative higher order function in Javascript. You can implement, for instance, map or filter in terms of reduce . I've used an imperative loop to better illustrate the algorithm: const foldL = f => acc => xs => { for (let i = 0; i < xs.length; i++) { acc = f(acc)(xs[i]); } return acc; }; const map = f => xs => { return foldL(acc => x => acc.concat([f(x)]))([])(xs); } let xs = [1, 2, 3, 4]; const inc = x => ++x; map(inc)(xs); // [2, 3, 4, 5] But

How do I break out of a loop in Haskell?

时光总嘲笑我的痴心妄想 提交于 2019-12-04 04:56:53
The current version of the Pipes tutorial , uses the following two functions in one of the example: stdout :: () -> Consumer String IO r stdout () = forever $ do str <- request () lift $ putStrLn str stdin :: () -> Producer String IO () stdin () = loop where loop = do eof <- lift $ IO.hIsEOF IO.stdin unless eof $ do str <- lift getLine respond str loop As is mentinoed in the tutorial itself, P.stdin is a bit more complicated due to the need to check for the end of input. Are there any nice ways to rewrite P.stdin to not need a manual tail recursive loop and use higher order control flow

IEnumerable foreach, do something different for the last element

风流意气都作罢 提交于 2019-12-04 01:24:59
I have an IEnumerable<T> . I want to do one thing for each item of the collection, except the last item, to which I want to do something else. How can I code this neatly? In Pseudocode foreach (var item in collection) { if ( final ) { g(item) } else { f(item) } } So if my IEnumerable were Enumerable.Range(1,4) I'd do f(1) f(2) f(3) g(4). NB. If my IEnumerable happens to be length 1, I want g(1). My IEnumerable happens to be kind of crappy, making Count() as expensive as looping over the whole thing. Since you mention IEnumerable[<T>] (not IList[<T>] etc), we can't rely on counts etc: so I

How to “break” out of a case…while in Ruby

て烟熏妆下的殇ゞ 提交于 2019-12-04 00:13:41
So, I've tried break , next and return . They all give errors, exit of course works, but that completely exits. So, how would one end a case...when "too soon?" Example: case x when y; begin <code here> < ** terminate somehow ** > if something <more code> end end (The above is some form of pseudo-code just to give the general idea of what I'm asking [begin...end was used with the hope that break would work]. And, while I'm at it, is there a more elegant way of passing blocks to case...when ? What's wrong with: case x when y; <code here> if !something <more code> end end Note that if !something

What is the best control flow module for node.js?

流过昼夜 提交于 2019-12-03 22:46:17
I've used caolan's async module which is very good, however tracking errors and the varying way of passing data through for control flow causes development to sometimes be very difficult. I would like to know if there are any better options, or what is currently being used in production environments. Thanks for reading. I use async as well. To help tracking errors it's recommended you name your functions, instead of having loads of anonymous functions: async.series([ function doSomething() {...}, function doSomethingElse() {...}, function finish() {...} ]); This way you'll get more helpful

Convincing Swift that a function will never return, due to a thrown Exception

纵然是瞬间 提交于 2019-12-03 16:32:12
问题 Because Swift does not have abstract methods, I am creating a method whose default implementation unconditionally raises an error. This forces any subclass to override the abstract method. My code looks like this: class SuperClass { func shouldBeOverridden() -> ReturnType { let exception = NSException( name: "Not implemented!", reason: "A concrete subclass did not provide its own implementation of shouldBeOverridden()", userInfo: nil ) exception.raise() } } The problem: Because the function