View EitherSample.scala
import scalaz._
import scala.util.Random
object EitherSample{
def main(args: Array[String]): Unit ={
println(for {
foo <- doAction("foo")
bar <- doAction("hoo")
} yield{
for{
View Node list as Array
let nodeList = document.querySelectorAll("div")
[].forEach.call(nodeList, a => console.log(a.innerText));
View hello-world.html
<script>
class HelloWorld extends HTMLElement{
constructor(){
//always first
super()
const shadow = this.attachShadow({mode:'open'});
shadow.innerHTML =
`
<style>
.content {
View State.ts
export class StateTuple<A, S>{
a: A
s: S
}
export class State<S, A>{
run = null;
constructor(run: (S) => StateTuple<A, S>){
this.run = run;
View index.html
<div class="ppap">
</div>
View sushi-console.js
const STR_LEN = 80
const SUSHI_INTERVAL =10
let cnt = 0;
function sushiDraw(){
const sa = new Array(STR_LEN).fill(' ')
for(let i = 0; i < STR_LEN; i += SUSHI_INTERVAL){
const sushiIndex = sa.length - 1 - (cnt + i) % sa.length
sa.splice(sushiIndex, 1, '🍣')
}
View Either.ts
export abstract class Either<T, U>{
abstract isRight(): boolean;
abstract fold<X>(l: (t: T) => X, r: (u: U) => X): X;
isLeft(): boolean{
return !this.isRight();
}
map<B>(f: (U) => B): Either<T, B>{
return this.fold(
View brace-open-one.exs
defmodule OpenBrace do
def regex(str) do
regex = ~r/\{.*\}/
match_strs = Regex.scan(regex, str)
remain_strs = Regex.split(regex, str)
ary = Enum.map(match_strs, fn(x) ->
match_str = to_string(x)
match_array = String.split(match_str, ",")
View caeser.exs
defmodule Caeser do
def caesar([], n), do: []
def caesar([head | tail], n) when head + n <= ?z, do: [head + n | caesar(tail, n)]
def caesar([head | tail], n), do: [head + n - (?z - ?a + 1) | caesar(tail, n)]
end
View mylist.exs
defmodule MyList do
def mapsum(array, func), do: Enum.reduce(array, 0, &(&2 + func.(&1)))
def max(array), do: Enum.reduce(array, nil, fn(v, arr) ->
case arr do
nil -> v
x when v <= x -> x
x when v > x -> v
end