我有两种可能的URL字符串形式
http://www.abcexample.com/landpage/?pps=[Y/lyPw==;id_1][Y/lyP2ZZYxi==;id_2];[5403;ord];
http://www.abcexample.com/landpage/?pps=Y/lyPw==;id_1;unknown;ord;
Run Code Online (Sandbox Code Playgroud)
我想Y/lyPw==在两个例子中得出结论
所以;id_1括号之间的所有内容
将永远属于该?pps=部分
解决这个问题的最佳方法是什么?我想使用大查询语言,因为这是我的数据所在
我正在match使用结构,并且想使用火柴后卫。但是,该结构是可变的,并且匹配臂左侧的绑定变量似乎引起单独借用。然后,这将触发编译错误,因为在可变借贷未偿还的情况下,您不能再借(可变或不可变)。
struct A(u8);
impl A {
fn is_awesome(&self) -> bool { true }
}
struct Container(A);
impl Container {
fn update(&mut self) {}
fn do_a_thing(&mut self) {
match *self {
Container(ref a) if a.is_awesome() => self.update(),
_ => {},
}
}
}
fn main() {}
Run Code Online (Sandbox Code Playgroud)
struct A(u8);
impl A {
fn is_awesome(&self) -> bool { true }
}
struct Container(A);
impl Container {
fn update(&mut self) {}
fn do_a_thing(&mut self) {
match *self {
Container(ref a) if a.is_awesome() …Run Code Online (Sandbox Code Playgroud) 我遇到了一个我不太懂的问题.我以为我可以在Haskell中编写这样的代码:
foo :: Maybe Int -> Int
foo Nothing = 0
foo Just x = x
Run Code Online (Sandbox Code Playgroud)
但是当我尝试编译它时,我收到错误:
'foo'的等式具有不同数量的参数
我可以通过将我的代码更改为以下代码来修复它:
foo :: Maybe Int -> Int
foo Nothing = 0
foo (Just x) = x
Run Code Online (Sandbox Code Playgroud)
这让我觉得GHC正在解释Just为一个论据foo.但是Haskell禁止使用大写字母来启动变量名,所以我不认为这里应该有任何歧义.这是怎么回事?
考虑下面的代码:
val first = ...
val second = ...
val third = ...
val fours = ...
first match {
case "someString" => second match {
case s:String => third match {
case MyEnum.A => //some logic
case MyEnum.B => fours match {
case Some(old:String) => //some other logic
case default=> defaulLogic
}
case default=> defaulLogic
}
case default=> defaulLogic
}
case default=> defaulLogic
}
private def defaulLogic()= {
//log error here
}
Run Code Online (Sandbox Code Playgroud)
有没有办法将case default逻辑放在一个地方而不是在每个模式匹配中复制它?
注意
只有顶部的match-case …
模式匹配是否可以匹配一系列值?例如 :
有没有办法使用以下形式的区别联合与活动模式匹配?我找不到任何例子.
这就是我想要做的:
type c = a | b
type foo =
| bar1
| bar2 of c
//allowed
let (|MatchFoo1|_|) aString =
match aString with
| "abcd" -> Some bar1
| _ -> None
//not allowed
let (|MatchFoo2|_|) aString =
match aString with
| "abcd" -> Some (bar2 of a)
| _ -> None
Run Code Online (Sandbox Code Playgroud)
为什么"Some"不能以第二种方式使用?还有另一种方法可以达到同样的目的吗?
这无法编译:
Array[Byte](...) match { case Array(0xFE.toByte, 0xFF.toByte, tail @ _* ) => tail }
Run Code Online (Sandbox Code Playgroud)
但是,我可以编译这个:
val FE = 0xFE.toByte
val FF = 0xFF.toByte
bytes match { Array( FE, FF, tail @ _* ) => tail }
Run Code Online (Sandbox Code Playgroud)
为什么第一种情况不能编译而不是第二种情况?
我想在Haskell中将Maybe Int转换为Int,如下所示:
convert :: Maybe Int -> Int
convert mx = case mx of
Just x -> x
Nothing -> error "error message"
Run Code Online (Sandbox Code Playgroud)
当我编译它时,Haskell告诉我:parse error on input 'Nothing'.
我需要这个,因为我想从Data.List模块中使用elem.Index函数获取列表中元素的索引,然后在take函数上使用此索引.我的问题是elemIndex返回a Maybe Int,但take需要一个Int.
这是对jsonb键/值的模式匹配的后续跟进
我有一张桌子如下
CREATE TABLE "PreStage".transaction (
transaction_id serial NOT NULL,
transaction jsonb
CONSTRAINT pk_transaction PRIMARY KEY (transaction_id)
);
Run Code Online (Sandbox Code Playgroud)
我的事务jsonb列中的内容看起来像
{"ADDR": "abcd", "CITY": "abcd", "PROV": "",
"ADDR2": "",
"ADDR3": "","CNSNT": "Research-NA", "CNTRY": "NL", "EMAIL": "@.com",
"PHONE": "12345", "HCO_NM": "HELLO", "UNQ_ID": "",
"PSTL_CD": "1234", "HCP_SR_NM": "", "HCP_FST_NM": "",
"HCP_MID_NM": ""}
Run Code Online (Sandbox Code Playgroud)
我需要搜索查询,如:
SELECT transaction AS data FROM "PreStage".transaction
WHERE transaction->>'HCP_FST_NM' ILIKE '%neer%';
Run Code Online (Sandbox Code Playgroud)
但我需要让我的用户灵活地搜索任何键/值.
对上一个问题的回答建议将索引创建为:
CREATE INDEX idxgin ON "PreStage".transaction
USING gin ((transaction->>'HCP_FST_NM') gin_trgm_ops);
Run Code Online (Sandbox Code Playgroud)
哪个有效,但我也想索引其他键.因此尝试了类似的事情:
CREATE INDEX idxgin ON "PreStage".transaction USING gin …Run Code Online (Sandbox Code Playgroud) pattern-matching ×10
haskell ×3
scala ×3
f# ×1
ghc ×1
indexing ×1
jsonb ×1
maybe ×1
parse-error ×1
postgresql ×1
regex ×1
rust ×1
string ×1