Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

with Cats, I can write this simple program

def foo(x: Int) = x + 1 val bar = Functor[Future](foo) 

and Now I can do a bar(future(1)) and get a Future.Success(2) as a result. Very good.

But suppose my function was

def foo[T](x: T)(implicit m: Manifest[T]) : String = {...} 

Now if I try to lift this function

def futureFoo = Functor[Future].lift(foo) 

I get a compiler error No Manifest available for T.

So how do I lift this function?

I searched and found this thread (which is for scalaz)

Lifting a function which takes implicit parameter using functor (Scalaz7)Lifting a function which takes implicit parameter using functor (Scalaz7)

But I still couldn't create anything which worked for me. I tried

val futureFoo = Functor[T].lift2(foo[T] _) 

but this doesn't compile

with Cats, I can write this simple program

def foo(x: Int) = x + 1 val bar = Functor[Future](foo) 

and Now I can do a bar(future(1)) and get a Future.Success(2) as a result. Very good.

But suppose my function was

def foo[T](x: T)(implicit m: Manifest[T]) : String = {...} 

Now if I try to lift this function

def futureFoo = Functor[Future].lift(foo) 

I get a compiler error No Manifest available for T.

So how do I lift this function?

I searched and found this thread (which is for scalaz)

Lifting a function which takes implicit parameter using functor (Scalaz7)

But I still couldn't create anything which worked for me. I tried

val futureFoo = Functor[T].lift2(foo[T] _) 

but this doesn't compile

with Cats, I can write this simple program

def foo(x: Int) = x + 1 val bar = Functor[Future](foo) 

and Now I can do a bar(future(1)) and get a Future.Success(2) as a result. Very good.

But suppose my function was

def foo[T](x: T)(implicit m: Manifest[T]) : String = {...} 

Now if I try to lift this function

def futureFoo = Functor[Future].lift(foo) 

I get a compiler error No Manifest available for T.

So how do I lift this function?

I searched and found this thread (which is for scalaz)

Lifting a function which takes implicit parameter using functor (Scalaz7)

But I still couldn't create anything which worked for me. I tried

val futureFoo = Functor[T].lift2(foo[T] _) 

but this doesn't compile

Source Link
Knows Not Much
  • 31.8k
  • 66
  • 208
  • 395

Lifting Functions using Cats Functor

with Cats, I can write this simple program

def foo(x: Int) = x + 1 val bar = Functor[Future](foo) 

and Now I can do a bar(future(1)) and get a Future.Success(2) as a result. Very good.

But suppose my function was

def foo[T](x: T)(implicit m: Manifest[T]) : String = {...} 

Now if I try to lift this function

def futureFoo = Functor[Future].lift(foo) 

I get a compiler error No Manifest available for T.

So how do I lift this function?

I searched and found this thread (which is for scalaz)

Lifting a function which takes implicit parameter using functor (Scalaz7)

But I still couldn't create anything which worked for me. I tried

val futureFoo = Functor[T].lift2(foo[T] _) 

but this doesn't compile