pattern-matching

How to avoid calling asInstanceOf in Scala

Deadly 提交于 2021-02-08 14:08:52
问题 Here is a simplified version of my code. How can I avoid to call asInstanceOf (because it is a smell for a poorly design solution) ? sealed trait Location final case class Single(bucket: String) extends Location final case class Multi(buckets: Seq[String]) extends Location @SuppressWarnings(Array("org.wartremover.warts.AsInstanceOf")) class Log[L <: Location](location: L, path: String) { // I prefer composition over inheritance // I don't want to pass location to this method because it's a

Powershell for Matching and Replacing Partially Matching Patterns

被刻印的时光 ゝ 提交于 2021-02-08 06:39:38
问题 Been going crazy all week unable to solve this issue. I have a dictionary word file that will be a few million words at one point, for now let's assume it's just a text file "Words.txt" which has: App Apple Application Bar Bat Batter Cap Capital Candy What I need it to do is to match each string against the rest of the file and only write output of the first hit. This will be alphabetical. Example the desired output from the words above would be: App - due to pattern "App" being seen first

VI delete everything except a pattern

不打扰是莪最后的温柔 提交于 2021-02-07 22:32:30
问题 I have a huge JSON output and I just need to delete everything except a small string in each line. The string has the format "title": "someServerName" the "someServerName" (the section within quotes) can vary wildly. The closest I've come is this: :%s/\("title":\s"*"\) But this just manages to delete "title": " The only thing I want left in each line is "title": "someServerName" EDIT to answer the posted question: The Text I'm going to be working with will have a format similar to {"_links":

VI delete everything except a pattern

我怕爱的太早我们不能终老 提交于 2021-02-07 22:31:05
问题 I have a huge JSON output and I just need to delete everything except a small string in each line. The string has the format "title": "someServerName" the "someServerName" (the section within quotes) can vary wildly. The closest I've come is this: :%s/\("title":\s"*"\) But this just manages to delete "title": " The only thing I want left in each line is "title": "someServerName" EDIT to answer the posted question: The Text I'm going to be working with will have a format similar to {"_links":

xpath - using contains with a wildcard

老子叫甜甜 提交于 2021-02-07 12:49:17
问题 I have the following, and trying to see if there's a better approach. I know it cn be done using starts-with/contains. I'm testing with firefox 10, which I believe implements xpath 2.+. Test node is <a id="foo"> . . . <a id="foo1"> . <a id="foo2"> Is there a way to use wildcards to be able to get the foo1/foo2 nodes.. Something like //a[@id =* 'foo'] or //a[contains(@id*,'foo')] Which would say, give me the "a" where the id starts with "foo" but has additional chars... This would then skip

Elegant pattern matching on nested tuples of arbitrary length

折月煮酒 提交于 2021-02-07 11:46:54
问题 I'm developing a composable functional UI library in F#, and I ran into a situation where I need to be able to create "collections" of items of heterogenous types. I don't want to accomplish this by resorting to dynamic programming and casting everything to obj (technically possible here, esp. since I'm compiling with Fable). Instead I want to retain as much type safety as possible. The solution I came up with is to create a simple custom operator %%% that builds tuples and then use it as

Multiply regex matches and replace them in string

可紊 提交于 2021-02-04 18:41:30
问题 I'm trying to multiply the amounts in a recipe using regex replace. Here is the example HTML code <div id="ingredients"> <ul> <li>2 bananas, sliced</li> <li>1 cup frozen strawberries</li> <li>8 oz. low fat vanilla yogurt</li> </ul> </div> I got as far as here. I'm trying to find a way to multiply the matched number and then replace the old one with the multiplied one: var str = document.getElementById('ingredients').innerHTML; var regex = /[0-9]+(?:\.[0-9]*)?/g; str = str.replace(regex, "$&"

Add a new line after a matched pattern in Notepad++

…衆ロ難τιáo~ 提交于 2021-02-02 09:52:40
问题 I have a csv-file, now i need to bring it in another form. I want to have a line break \r\n after a specific pattern. All patterns look like this: true or false; int number between 0 and 100; decimal number with two or three digits after the point; true or false; For example: false;2;23.987;false; true;0;8.37;false; false;8;166.987;false; and after the last semicolon, i want to have a line break. I am using notepad++. Thanks for your help 回答1: You may use \b(?:true|false);\d+;\d+\.\d+;(?:true

Add a new line after a matched pattern in Notepad++

痴心易碎 提交于 2021-02-02 09:50:46
问题 I have a csv-file, now i need to bring it in another form. I want to have a line break \r\n after a specific pattern. All patterns look like this: true or false; int number between 0 and 100; decimal number with two or three digits after the point; true or false; For example: false;2;23.987;false; true;0;8.37;false; false;8;166.987;false; and after the last semicolon, i want to have a line break. I am using notepad++. Thanks for your help 回答1: You may use \b(?:true|false);\d+;\d+\.\d+;(?:true

Add a new line after a matched pattern in Notepad++

本秂侑毒 提交于 2021-02-02 09:50:09
问题 I have a csv-file, now i need to bring it in another form. I want to have a line break \r\n after a specific pattern. All patterns look like this: true or false; int number between 0 and 100; decimal number with two or three digits after the point; true or false; For example: false;2;23.987;false; true;0;8.37;false; false;8;166.987;false; and after the last semicolon, i want to have a line break. I am using notepad++. Thanks for your help 回答1: You may use \b(?:true|false);\d+;\d+\.\d+;(?:true