I hereby claim:
- I am lokeh on github.
- I am lilactown (https://keybase.io/lilactown) on keybase.
- I have a public key ASCapdmYRqCZdN5lH20UYAK97qiesOSuzTC7P68aBL04Xwo
To claim this, I am signing this object:
module type Promise = { | |
type t 'a; | |
let then_: ('a => t 'b) => t 'a => t 'b; | |
let resolve: 'a => t 'a; | |
let all: array (t 'a) => t (array 'a); | |
let race: array (t 'a) => t 'a; | |
let make: (resolve::('a => unit) [@bs] => reject::(exn => unit) [@bs] => unit) => t 'a; | |
}; | |
module Make (P: Promise) => { |
fetch('/endpoint') | |
.then(res => { | |
if (res.ok) { | |
return res.json(); | |
} | |
throw new Error(res.statusText); | |
}) | |
// handle response here | |
.then(({ status, payload }) => { | |
switch (status) { |
/** | |
* Making promises | |
*/ | |
let okPromise = Js.Promise.make((~resolve, ~reject as _) => [@bs] resolve("ok")); | |
/* Simpler promise creation for static values */ | |
Js.Promise.resolve("easy"); | |
Js.Promise.reject(Invalid_argument("too easy")); |
external _unfold : ('a => Js.t 'whatever) => 'a => stream 'b = "unfold" [@@bs.module "most"]; | |
module Unfold = { | |
type t 'value 'seed = | |
| Value 'value 'seed | |
| Done; | |
}; | |
external convertUnfoldValue : Js.t {. _done : bool} => Js.t {. seed : 'a, value : 'b} = | |
"%identity"; |
let fizzbuzz num => { | |
let shouldFizz = num mod 3 == 0; | |
let shouldBuzz = num mod 5 == 0; | |
switch (shouldFizz, shouldBuzz) { | |
| (true, true) => "FizzBuzz" | |
| (true, false) => "Fizz" | |
| (false, true) => "Buzz" | |
| (false, false) => string_of_int num | |
} | |
}; |
;; Something similar to this goes in project.clj: | |
;; | |
;; :profiles {:dev {:dependencies [[com.cemerick/piggieback "0.2.2"] | |
;; [figwheel-sidecar "0.5.10"]] | |
;; :source-paths ["ui_src" "dev"]}} | |
(ns user | |
(:require [figwheel-sidecar.repl-api :as ra])) | |
(defn fig-start [] (do |
type Reduced<Value> = { value: Value, completed: boolean }; | |
type Reducer<Accumulator, Input> = (whatever: Accumulator, input: Input) => Accumulator | Reduced<Accumulator>; | |
type Transducer<Input, Output> = | |
<Accumulator>(reducer: Reducer<Accumulator, Output>) => Reducer<Accumulator, Input>; | |
// utils | |
function reduced<Value>(value: any, completed: boolean): Reduced<Value> { | |
return { value, completed }; | |
} |
(ns lilactown.promise) | |
;; This is a simple macro to aid with dealing with promise chains | |
;; in ClojureScript. Often external JS libraries (such as request-promise | |
;; or other async libs) return a promise object, so we write code like: | |
;; | |
;; (-> promise-value | |
;; (.then do-something) | |
;; (.then #(do-something-else %)) | |
;; (.then (fn [val] (and-again val))) |
#!/bin/bash | |
########################## | |
# Description: | |
# Downloads an Erlang program from a Gist or Hastebin, then opens an Erlang shell with it | |
# compiled and loaded. | |
# | |
# Installation: | |
# Download and install this script in /usr/local/bin | |
# |
I hereby claim:
To claim this, I am signing this object: