Jun. 27th, 2014

juan_gandhi: (VP)
"Стало відомо, чому російські "козаки" так ломляться на Донбас: їм платять по 300 доларів в день, а вони наймають місцевих гопників за 100 доларів в день воювати замість себе - таким чином, нічого не роблячи і нічим не ризикуючи, залишають собі по 200 доларів в день + займаються мародерством!"
juan_gandhi: (VP)
       Good("huilo") filter ((s:String) => s.startsWith("he"), "oi vei") must_== Result.error("oi vei")
juan_gandhi: (VP)
- what are they?
Classes of types, not formally declared as classes, as they usually do in Java/Scala.
- why?
To provide common, context-based ad-hoc operations, not provided by the types (since we don't want to). E.g. you have a traditional Java array, and you want it to be smarter.

- where do I declare additional operations?
Declare a parameterized trait e.g. NewOps[T] that describes the type class with functionality applicable to T.

- where do I define additional operations?
In an implicit witness object implementing the trait.

- how do I use it?
(Using pimp pattern) define an implicit function that takes an instance of T returning an instance having additional operations. Define a witness in this function implicitly - compiler will find it. Call witness object to do the job inside this new instance.

- how come the right functionality is involved?
Compiler finds the right witness object based on the parameter type. Make sure there's exactly one visible for your type.

==========
P.S. correct me if I am wrong.

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

August 2025

S M T W T F S
      12
3456789
10 11 12 13141516
171819 20212223
2425 2627282930
31      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 30th, 2025 04:33 am
Powered by Dreamwidth Studios