enrich-my-library Questions

1

Solved

I recently discovered that one can use the Pimp Enrich My Library pattern to add methods to companion objects using .type: object Whatever { } implicit class WhateverExtensions(val obj: Whatever....
Jasmine asked 19/5, 2015 at 23:24

4

In Scala 2.9 to add custom methods to a library class (enrich or "pimp" it) I had to write something like this: object StringPimper { implicit def pimpString(s: String) = new { def greet: String...
Lengthwise asked 10/2, 2013 at 20:58

3

Solved

I've got a class from a library (specifically, com.twitter.finagle.mdns.MDNSResolver). I'd like to extend the class (I want it to return a Future[Set], rather than a Try[Group]). I know, of course...
Pyrogallol asked 12/6, 2013 at 17:59

1

Solved

I was trying to figure out how to write a functional swap function that works on any Traversable[_], given a collection and the indexes to swap. I came up with the following: def swap[A, CC <% ...
Nitriding asked 29/3, 2013 at 18:28

1

Solved

Scala 2.10 introduces value classes, which you specify by making your class extend AnyVal. There are many restrictions on value classes, but one of their huge advantages is that they allow extensio...
Schumacher asked 13/2, 2013 at 19:52

3

Solved

One of the most powerful patterns available in Scala is the enrich-my-library* pattern, which uses implicit conversions to appear to add methods to existing classes without requiring dynamic method...
Judsen asked 23/3, 2011 at 19:54

1

Solved

When working with Java from Scala, we have to account for null. HttpServletRequest getters (getAttribute, getHeader, etc.) for example, all potentially return null. I know I can manually do a ca...
Deannedeans asked 6/4, 2012 at 19:37

1

Solved

The are two different way to implement it. One is more short implicit def toR1(s:String) = new { def getLength = s.length)} Second is more long class R2(s:String){def getLength2 = s.length)} i...
Cailly asked 22/2, 2012 at 20:12

5

Solved

Im looking to extended the iterator to create a new method takeWhileInclusive, which will operate like takeWhile but include the last element. My issue is what is best practice to extend the itera...
Chromolithography asked 17/2, 2012 at 14:21

3

Solved

Say I have a method that turns a (function on two elements) into a (function on two sequences): def seqed[T](f: (T,T) => T): (Seq[T], Seq[T]) => Seq[T] = (_,_).zipped map f In words, the r...

2

Solved

The toInt method in StringLike doesn't take any arguments, and can only parse in decimal. So to parse binary, hex etc we need to resort to Java's Integer#parseInt(String s, int radix). In an attem...
Carbonation asked 27/10, 2011 at 19:29

3

Solved

Suppose one wants to build a novel generic class, Novel[A]. This class will contain lots of useful methods--perhaps it is a type of collection--and therefore you want to subclass it. But you want t...
1

© 2022 - 2024 — McMap. All rights reserved.