我目前正在尝试使用嵌入式elixir(在我的例子中是.html.eex文件).我知道如何渲染elixir哈希,但我无法弄清楚如何创建显示列表中所有项目的内容.在Ruby中它会像这样工作:
<% array.each do |item| %>
<p> <%= item %> </p>
<% end %>
Run Code Online (Sandbox Code Playgroud) 我有一个流,其中包含大量的值.我正在寻找一种过滤掉Either-Left和Either-Right上的地图的不道德的方法.我想避免类似的事情
final case class Foo(x: Either[String, Int], y:Int)
val foos = functionReturningSeqOfFoo()
Source(foos)
.filter(_.x.isRight)
.map(foo => (foo.x.right.get, foo.y))
.map { case (x, y) =>
doSomethingWith(x, y)
}
.runWith(Sink.seq)
Run Code Online (Sandbox Code Playgroud)
这是一个最小的例子.因为我的流非常长,所以这很混乱,并且感觉不是一个好方法.
顺便说一下,在我的情况下同样适用于Option [T].
我寻找一个光滑的相当于
select * from users where last_name ~* '[\w]*son';
Run Code Online (Sandbox Code Playgroud)
例如,当数据库中有以下名称时:
first_name | last_name
----------------------
Tore | Isakson
John | Smith
Solveig | Larsson
Marc | Finnigan
Run Code Online (Sandbox Code Playgroud)
结果是
first_name | last_name
----------------------
Tore | Isakson
Solveig | Larsson
Run Code Online (Sandbox Code Playgroud)
我当前的解决方案是使用 SQLActionBuilder 插入它,例如
val pattern = "[\\w]*son"
val action = sql""" SELECT * FROM users WHERE last_name ~* ${pattern}; """.as[User]
Run Code Online (Sandbox Code Playgroud)
但这不是我想要的方式。我更喜欢类似的东西
users.filter(_.last_name matchRegex "[\\w]*son") // <- This does not exist
Run Code Online (Sandbox Code Playgroud)
如果相关:我使用 Postgres。