Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
wyrażenia regularne
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
lkuczera  
View profile   Translate to Translated (View Original)
 More options Apr 22 2011, 4:20 am
From: lkuczera <kuk...@gmail.com>
Date: Fri, 22 Apr 2011 01:20:17 -0700 (PDT)
Local: Fri, Apr 22 2011 4:20 am
Subject: wyrażenia regularne
Witajcie.
Mam taki kod:
val r = "\\d\\d".r
val arr = "alkdjf 34 adlkjf 34 aldkjf".split

Teraz to co chcę zrobić to przeiterować tablicę zwracając None jeżeli
wyrażenie nie będzie pasowało do chociażby jednego elementu i przerwać
iterację lub zwrócić wydłubane wartości. Nie wiem jak to zrobić
funkcyjnie w jednym przbiegu iteracji.

Moje rozwiązanie to albo dwie iteracje albo poprzez var'y.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Maciej Biłas  
View profile   Translate to Translated (View Original)
 More options Apr 22 2011, 4:48 am
From: Maciej Biłas <maciej.bi...@gmail.com>
Date: Fri, 22 Apr 2011 10:48:01 +0200
Local: Fri, Apr 22 2011 4:48 am
Subject: Re: [psg] wyrażenia regularne
2011/4/22 lkuczera <kuk...@gmail.com>:

> Witajcie.
> Mam taki kod:
> val r = "\\d\\d".r
> val arr = "alkdjf 34 adlkjf 34 aldkjf".split

> Teraz to co chcę zrobić to przeiterować tablicę zwracając None jeżeli
> wyrażenie nie będzie pasowało do chociażby jednego elementu i przerwać
> iterację lub zwrócić wydłubane wartości. Nie wiem jak to zrobić
> funkcyjnie w jednym przbiegu iteracji.

> Moje rozwiązanie to albo dwie iteracje albo poprzez var'y.

arr.filter(r.findFirstIn(_) != None) match {
  case a if a.length > 0 => Some(a)
  case _ => None

}

Zwróci wszystkie 34-ki.

Podejrzewam, że tym wariantem byłeś zainteresowany. Jeżeli jednak
chciałeś tylko pierwszy wynik to skorzystaj po prostu z metody find.

Pozdrawiam,
Maciej
--
Maciej Biłas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »