I hereby claim:
- I am aarshkshah1992 on github.
- I am tambourineman (https://keybase.io/tambourineman) on keybase.
- I have a public key ASAPX7N9Mhhzoo7VRNA231UNmzM87QPcZbgUu5Ew8dNDqAo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
package main | |
import ( | |
"bytes" | |
"encoding/json" | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
"reflect" | |
) |
package main | |
import ( | |
"context" | |
"fmt" | |
"io" | |
"os" | |
"github.com/ipld/go-ipld-prime/datamodel" | |
"github.com/ipld/go-ipld-prime/traversal" |
def findMax[T](list: List[T])(implicit ordering: CustomOrdering[T]): T = { | |
list.reduce((a, b) => if (ordering >=(a, b)) a else b) | |
} |
import scalaz.Memo | |
val memoizedIsPrime: Int => Boolean = Memo.immutableHashMapMemo { | |
num => (2 to num - 1).forall(i => num % i != 0) | |
} |
/** Returns the value associated with a key, or a default value if the key is not contained in the map. | |
* @param key the key. | |
* @param default a computation that yields a default value in case no binding for `key` is | |
* found in the map. | |
*/ | |
def getOrElse[V1 >: V](key: K, default: => V1): V1 = get(key) match { | |
case Some(v) => v | |
case None => default | |
} |
/** Creates a new future by applying a function to the successful result of | |
* this future. If this future is completed with an exception then the new | |
* future will also contain this exception. | |
... | |
*/ | |
def map[S](f: T => S): Future[S] | |
/** Creates a new future by applying a function to the successful result of | |
* this future, and returns the result of the function as the new future. | |
* If this future is completed with an exception then the new future will |
import scalaz.Scalaz._ | |
def findSum(lst: List[String]): Future[ValidationNel[Throwable, Int]] = { | |
val futValidtionNels: Future[List[ValidationNel[Throwable, Int]]] = | |
Future.traverse(lst)(str => | |
Future(str.toInt).map(x => x.successNel[Throwable]).recover { | |
case ex => ex.failureNel | |
}) |
val output = Await.result(findSum(List("1", "2", "3")), 2 seconds) | |
//Output | |
output: Either[List[Throwable],Int] = Right(6) |
def findSum(lst: List[String]): Future[Either[List[Throwable], Int]] = { | |
val futTry: Future[List[Try[Int]]] = Future.traverse(lst)(str => | |
Future(str.toInt).map(Success(_)).recover { | |
case ex => Failure(ex) | |
}) | |
futTry.map(listTry => | |
listTry.foldLeft(Right(0): Either[List[Throwable], Int])((acc, tryResult) => (acc, tryResult) match { | |
case (Right(i1), Success(i2)) => Right(i1 + i2) |