This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| countOccurrences :: (Ord k, Num a) => (t -> k) -> [t] -> Map k a | |
| countOccurrences f xs = Map.fromListWith (+) [(f x, 1) | x <- xs] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| groupWith :: (Ord b) => (a -> b) -> [a] -> Map b [a] | |
| groupWith f xs = Map.fromListWith (++) [(f x, [x]) | x <- xs] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| partition :: [a] -> (a -> Bool) -> ([a], [a]) | |
| partition as f = (filter f as, filter (not . f) as) | |
| partition2 :: [a] -> (a -> Bool) -> ([a], [a]) | |
| partition2 as f = foldr combine ([], []) as | |
| where | |
| combine elem (ts, fs) = | |
| if f elem | |
| then (elem : ts, fs) | |
| else (ts, elem : fs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import cats.data.Validated | |
| class InvalidNameException extends Exception | |
| class InvalidEmailException extends Exception | |
| class InvalidAgeException extends Exception | |
| object Validations { | |
| def validateName(name: String): Validated[InvalidNameException, String] = | |
| if (name.isEmpty) Validated.Invalid(new InvalidNameException()) | |
| else Validated.Valid(name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import io.vavr.collection.Seq; | |
| import io.vavr.control.Validation; | |
| class Demo { | |
| public static void main(String[] args) { | |
| String name = "name"; | |
| String email = "ex@mple.com"; | |
| int age = 20; | |
| Validation<Seq<Exception>, User> user = Validation.combine( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import io.vavr.collection.Seq; | |
| import io.vavr.control.Validation; | |
| class Demo { | |
| public static void main(String[] args) { | |
| String name = "name"; | |
| String email = "foo@bar.com"; | |
| int age = 20; | |
| Validation<Seq<UserError>, User> user = Validation.combine( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import io.vavr.collection.Seq; | |
| import io.vavr.control.Validation; | |
| class Demo { | |
| public static void main(String[] args) { | |
| String name = "name"; | |
| String email = "ex@mple.com"; | |
| int age = 20; | |
| Validation<Seq<Exception>, User> user = Validation.combine( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.l7r7.lab.feed.client | |
| import akka.actor.ActorSystem | |
| import akka.http.scaladsl.Http | |
| import akka.http.scaladsl.model._ | |
| import akka.http.scaladsl.model.headers.Link | |
| import akka.http.scaladsl.unmarshalling.Unmarshal | |
| import akka.stream.scaladsl.Source | |
| import akka.stream.{ ActorMaterializer, Materializer } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.l7r7.lab.feed.client | |
| import akka.actor.ActorSystem | |
| import akka.http.scaladsl.Http | |
| import akka.http.scaladsl.model.Multipart.General | |
| import akka.http.scaladsl.model._ | |
| import akka.http.scaladsl.model.headers.Link | |
| import akka.http.scaladsl.unmarshalling.Unmarshal | |
| import akka.stream.ActorMaterializer | |
| import akka.stream.scaladsl.{ Flow, Source } |
NewerOlder