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 akka.stream.FlowShape | |
import akka.stream.scaladsl.{Flow, GraphDSL, Source, Zip} | |
import scala.concurrent.duration.FiniteDuration | |
object RateLimiter { | |
private def rateLimiter[A](rate: FiniteDuration) = { | |
case object Tick |
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
module ListPermutations where | |
listPermutations :: [a] -> Integer -> [[a]] | |
listPermutations _ 0 = [[]] | |
listPermutations [] _ = [] | |
listPermutations (x:xs) n = fmap (x:) (listPermutations xs (n - 1)) ++ listPermutations xs n |
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
defmodule ListPermutations do | |
def list_permutations(_, 0), do: [[]] | |
def list_permutations([], _), do: [] | |
def list_permutations([h|t], n), do: Enum.map(list_permutations(t, n-1), fn(l) -> [h|l] end) ++ list_permutations(t, n) | |
end |
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
module ListPermutations where | |
listPermutations :: Integer => [a] -> b -> [[a]] | |
listPermutations l n = snd $ permutate l n | |
where permutate :: Integer => [a] -> b -> ([[a]], [[a]]) | |
permutate [] _ = ([[]], []) | |
permutate (x:xs) n = let (pt, acc) = permutate xs n in permutateInner x pt pt acc n | |
where permutateInner :: Integer => a -> [[a]] -> [[a]] -> [[a]] -> b -> ([[a]], [[a]]) | |
permutateInner _ [] pt acc _ = (pt, acc) | |
permutateInner h (x:xs) pt acc n |
NewerOlder