Skip to content

Instantly share code, notes, and snippets.

import * as stout from 'readline-sync'
import { pipe, flow } from 'fp-ts/lib/function'
type Unit = any
const unit: void = undefined
type Console<A> = Return<A> | PrintLine<A> | ReadLine<A>
class Return<A> {
readonly _tag: "Return" = "Return"
/**
* EXERCISE
*
* Using `ZManaged.foreachPar` and other functions as necessary, implement a function
* to read the contents of all files in parallel, but ensuring that if anything
* goes wrong during parallel reading, all files are safely closed.
*/
def readFiles(
files: List[String]
): ZIO[Blocking with Console, IOException, Unit] =
trait Tree[+A]
case class Leaf[A](value: A, left: Tree[A], right: Tree[A]) extends Tree[A]
case object Empty extends Tree[Nothing]
type Distance[Node] = Map[Node, Int]
type Distances[Node] = Map[Node, Distance[Node]]
type PivotEquilibriumIndexes = List[Int]
def calculatePivot(lst: List[Int]) : PivotEquilibriumIndexes = {
lazy val sumLst = lst.tail.sum
def isAnEquilibrium(leftSum: Int, rightSum: Int) : Boolean = leftSum == rightSum
def iter(index: Int, leftList: Vector[Int], rightList: List[Int], leftSum: Int, rightSum: Int) : PivotEquilibriumIndexes = {
rightList match {
import java.util.concurrent.{Callable, ExecutorService, Future, TimeUnit}
import scala.util.Try
object ParallelModule {
type Par[A] = ExecutorService => Future[A]
%% Based on code from
%% Erlang Programming
%% Francecso Cesarini and Simon Thompson
%% O'Reilly, 2008
%% http://oreilly.com/catalog/9780596518189/
%% http://www.erlangprogramming.org/
%% (c) Francesco Cesarini and Simon Thompson
-module(frequency).
-export([start/0,allocate/0,deallocate/1,stop/0]).
-module(frequency_client).
-export([main/0]).
main() ->
PiD = spawn(frequency, init, []),
register(frequency, PiD).
-module(palin_server).
-export([server/1]).
-import(palin, [palindrome/1]).
server(From) ->
receive
{check,Msg} ->
case palindrome(Msg) of
true -> From ! {result, Msg ++ " is a palindrome"};
false -> From ! {invalid, "stopped"}
public static Map<String, String> convert(String[] s1, String[] s2) {
return Option.when(ArrayUtils.isSameLength(s1, s2), () -> s1.length)
.map(length -> Stream.range(0, length)
.toMap(index -> Tuple.of(s1[index], s2[index])))
.getOrElse(HashMap.empty());
}
@atrianac
atrianac / TestLocaleUnit.java
Last active November 26, 2015 09:36
Date / Time - Java 8
package com.digitaslbi.helios.util;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.TimeZone;
import org.junit.Test;