case-statement

Anonymous partial function in early initializer requires “premature access to class”

别来无恙 提交于 2019-12-02 01:27:06
Why does this fail to compile: trait Item trait StringItem extends Item { def makeString: String } trait SomeOtherItem extends Item trait DummyTrait case class Marquee(items: Seq[Item]) extends { val strings: Seq[String] = items.collect { case si: StringItem => si.makeString // <-- partial function inside braces } } with DummyTrait with the error message <$anon: Item => String> requires premature access to class Marquee ? It seems to me that the partial function makes no use of Marquee . Yet this compiles: val pf: PartialFunction[Item, String] = { case si: StringItem => si.makeString } case

Dealing with combining cases & duplicate cases in switch statements

泄露秘密 提交于 2019-12-01 11:54:09
问题 Is it okay to combine cases that share assignments and repeat the case for assignments that are not shared, or is it preferred to just keep each separated? To illustrate with a simple example.. case 0 and 180 both include w = 330 so they have been combined; the value assigned to x is different for each so they are repeated to do the x assignment. switch(window.orientation) { case 0: case 180: w = 330; //break case 0: x = '-180px'; //break case -90: case 90: w = 480; x = '0'; break; case 180:

Dealing with combining cases & duplicate cases in switch statements

风格不统一 提交于 2019-12-01 11:45:41
Is it okay to combine cases that share assignments and repeat the case for assignments that are not shared, or is it preferred to just keep each separated? To illustrate with a simple example.. case 0 and 180 both include w = 330 so they have been combined; the value assigned to x is different for each so they are repeated to do the x assignment. switch(window.orientation) { case 0: case 180: w = 330; //break case 0: x = '-180px'; //break case -90: case 90: w = 480; x = '0'; break; case 180: x = '-80px'; break; } When it comes to do more than one operation per element in a switch statement, it

Query with many CASE statements - optimization

℡╲_俬逩灬. 提交于 2019-11-30 17:35:37
问题 I have one very dirty query that per sure can be optimized because there are so many CASE statements in it! SELECT (CASE pa.KplusTable_Id WHEN 1 THEN sp.sp_id WHEN 2 THEN fw.fw_id WHEN 3 THEN s.sw_Id WHEN 4 THEN id.ia_id END) as Deal_Id, max(CASE pa.KplusTable_Id WHEN 1 THEN sp.Trans_Id WHEN 2 THEN fw.Trans_Id WHEN 3 THEN s.Trans_Id WHEN 4 THEN id.Trans_Id END) as TransId_CurrentMax INTO #MaxRazlicitOdNull FROM #PotencijalniAktuelni pa LEFT JOIN kplus_sp sp (nolock) on sp.sp_id=pa.Deal_Id AND

How to use patterns in a case statement?

牧云@^-^@ 提交于 2019-11-29 19:47:46
The man page says that case statements use "filename expansion pattern matching". I usually want to have short names for some parameters, so I go: case $1 in req|reqs|requirements) TASK="Functional Requirements";; met|meet|meetings) TASK="Meetings with the client";; esac logTimeSpentIn "$TASK" I tried patterns like req* or me{e,}t which I understand would expand correctly to match those values in the context of filename expansion, but it doesn't work. Brace expansion doesn't work, but * , ? and [] do. If you set shopt -s extglob then you can also use extended pattern matching : ?() - zero or

Pattern matching variables in a case statement in Haskell

被刻印的时光 ゝ 提交于 2019-11-29 06:19:23
If I compare a string literal to a string literal using the case statement, I get the expected behavior: if they are the same - it matches, if they are not - it does not. However, if I compare a string literal to a constant that is a string, I get "Pattern matches are overlapped" warning and the branch with the constant always matches. Here's an example session: Prelude> let var1 = "abc" Prelude> let var2 = "def" Prelude> case var1 of { var2 -> "Fail"; _ -> "Win" } <interactive>:1:0: Warning: Pattern match(es) are overlapped In a case alternative: _ -> ... "Fail" Prelude> case "abc" of { var2

T-SQL Conditional WHERE Clause

六月ゝ 毕业季﹏ 提交于 2019-11-28 21:09:36
Found a couple of similar questions here on this, but couldn't figure out how to apply to my scenario. My function has a parameter called @IncludeBelow . Values are 0 or 1 (BIT). I have this query: SELECT p.* FROM Locations l INNER JOIN Posts p on l.LocationId = p.LocationId WHERE l.Condition1 = @Value1 AND l.SomeOtherCondition = @SomeOtherValue If @IncludeBelow is 0, i need the query to be this: SELECT p.* FROM Locations l INNER JOIN Posts p on l.LocationId = p.LocationId WHERE l.Condition1 = @Value1 AND l.SomeOtherCondition = @SomeOtherValue AND p.LocationType = @LocationType -- additional

How to use patterns in a case statement?

丶灬走出姿态 提交于 2019-11-28 16:17:05
问题 The man page says that case statements use "filename expansion pattern matching". I usually want to have short names for some parameters, so I go: case $1 in req|reqs|requirements) TASK="Functional Requirements";; met|meet|meetings) TASK="Meetings with the client";; esac logTimeSpentIn "$TASK" I tried patterns like req* or me{e,}t which I understand would expand correctly to match those values in the context of filename expansion, but it doesn't work. 回答1: Brace expansion doesn't work, but *

Verilog Barrel Shifter

只愿长相守 提交于 2019-11-28 11:34:04
I want to create a 64-bit barrel shifter in verilog (rotate right for now). I want to know if there is a way to do it without writing a 65 part case statement? Is there a way to write some simple code such as: Y = {S[i - 1:0], S[63:i]}; I tried the code above in Xilinx and get an error: i is not a constant. Main Question: Is there a way to do this without a huge case statment? I've simplified some of the rules for clarity, but here are the details. In the statement Y = {S[i - 1:0], S[63:i]}; you have a concatenation of two signals, each with a constant part select. A constant part select is of

Is it possible to perform a “LIKE” statement in a SSIS Expression?

泪湿孤枕 提交于 2019-11-28 08:25:44
I'm using a Derived Column Task to change column data using a CASE WHEN statement. However, I need to be able to say.. SQL CODE WOULD BE: CASE WHEN Column01 LIKE '%i%' THEN '0' ELSE '1' END In SSIS Expression Language that would be: [Column01] == "i" ? "0" : "1" (that's for equals i, not, LIKE %i%. Is it possible to use a LIKE operator? I believe you'll want to use the FINDSTRING function . FINDSTRING(character_expression, searchstring, occurrence) ... FINDSTRING returns null if either character_expression or searchstring are null. Guilherme de Jesus Santos I know it is an old question, but