Add for(value <- items)
and for(value, offset <- items)
to Sweet.js
for(x <- [1,2,3,4]) {
var a = x + 10;
print(a);
}
(import '[javax.script ScriptEngineManager]) | |
(let [engine (.getEngineByName (ScriptEngineManager.) "nashorn")] | |
(println (= (.eval engine "' \\r\\n' == 0") true))) |
macro null_helper { | |
rule { ($processed ...) ($rest) } => { | |
$processed (.) ... . $rest | |
} | |
rule { ($processed ...) ($rest_head $rest ...) } => { | |
$processed (.) ... . $rest_head | |
&& null_helper ($processed ... $rest_head) ($rest ...) | |
} | |
} | |
(defn flatmap< | |
"Takes a function and a source channel, and returns a channel which | |
contains the values in each channel produced by applying f to | |
each value taken from the source channel. f must return a | |
channel." | |
[f in] | |
(let [out (a/chan)] | |
(a/go-loop [] | |
(let [item (a/<! in)] | |
(if (nil? item) |
// The DSL's implementation (i.e. just the applicative interface for Optionals + methods for creating tuples) | |
operator infix <*> { associativity left } | |
@infix func <*><A, B>(lhs: (A -> B)?, rhs: A?) -> B? { | |
switch lhs { | |
case .None: | |
return .None | |
case let .Some(f): | |
return rhs.map(f) | |
} | |
} |
macro protocol { | |
case { _ $name:ident { $fn:protocol_fn ... } } => { | |
// Probably not a good idea to rely on `__fresh`. Sweet.js should provide | |
// some sort of blessed gensym capability. | |
letstx $id = [makeValue(__fresh(), #{ here })]; | |
return #{ | |
function $name(proto, impl) { | |
if (!impl) { | |
impl = proto; | |
proto = {}; |
I think of Schema as a runtime contracts library (I believe it does coercion and validation, but they seem related to me).
scala> case class UserId(id: Long) | |
defined class UserId | |
scala> def isSusan(id: UserId): Boolean = id == 3L // see the bug? | |
isSusan: (id: UserId)Boolean | |
scala> isSusan(UserId(3L)) | |
res31: Boolean = false// shouldn't this be true? | |
// let's show the compiler how to check whether two UserIds are equal |
(ns kebab | |
(:require [camel-snake-kebab :as kebab] | |
[schema.coerce :as c] | |
[schema.core :as s])) | |
(def Data (s/either s/Keyword | |
{(s/recursive #'Data) (s/recursive #'Data)} | |
[(s/recursive #'Data)] | |
#{(s/recursive #'Data)} | |
s/Any)) |
public static final Answer DEFAULT_OPTIONAL_EMPTY_ANSWER = invocation -> | |
invocation.getMethod().getReturnType() == Optional.class ? Optional.empty() : null; | |
Mockito.mock(YourClassWithOptionalReturnValues.class, DEFAULT_OPTIONAL_EMPTY_ANSWER); | |
// unfortunately this does not work since Mockito's Answers enum is not extendable (yet, issue 345) | |
@Mock(answer = DEFAULT_OPTIONAL_EMPTY_ANSWER) | |
private YourClassWithOptionalReturnValues mockInstance; |