implicit conversion - Dedicated Scala String interpolation -


दिए गए नक्शा स्थिरांक के लिए

  val ctt = मैप ("ए" -> 1) "<">        
  c "a"   

उद्धार करता है सूची (1) ?

नोट

  सी "a, b" res: सूची (1, 2) सी "ए, बी" रिज़ः सूची (1,2) सी "ए, डब्ल्यू" रिज़ः सूची (1) सी "डब्ल्यू" रिज़ः सूची ()    < P> 

निम्न कार्य करता है:

  scala & gt; वैल सीटीटी = नक्शा ("ए" - & gt; 1, 'बी' - & gt; 2) सीटीटी: स्कला। कोलिन्शन.इमट्यूबल। मैप [स्ट्रिंग, इंट] = नक्शा (ए -> 1, बी - & gt; 2) स्केला & gt; अंतर्निहित वर्ग CttHelper (val sc: StringContext) AnyVal तक फैलता है {| Def c (आर्ग्स: कोई *): Int = ctt (sc.parts.head) | } परिभाषित वर्ग CttHelper scala & gt; सी "ए" res0: Int = 1   

या अपने अद्यतन संस्करण के लिए:

  अंतर्निहित वर्ग CttHelper (val sc: StringContext) AnyVal {def c (आर्ग्स: कोई *): सूची [इंट] = sc.parts.head.split (',')। नक्शा (_। ट्रिम) .toList.flatMap (ctt.get)}   < P> और फिर:  
  स्कला & gt; C "a, w" res5: सूची [int] = सूची (1) स्केल & gt; सी "ए, बी" रिज 6: सूची [इंट] = सूची (1, 2) स्केल & gt; सी "ए, बी" रिज 7: सूची [इंट] = सूची (1, 2) स्केल & gt; C "a, w" res8: सूची [इंट] = सूची (1) स्केल & gt; C "w" res9: सूची [इंट] = सूची ()   

आप शायद यह जांचना चाहते हैं कि sc.parts में एक तत्व है, हालांकि, जब तक कि आप वास्तव में इंटरपोलेटेड चर के साथ कुछ करना चाहते हैं।

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -