diff --git a/src/core/core.janet b/src/core/core.janet index 7c4e5057..5f81334c 100644 --- a/src/core/core.janet +++ b/src/core/core.janet @@ -741,7 +741,7 @@ (defmacro -> "Threading macro. Inserts x as the second value in the first form - in form, and inserts the modified firsts form into the second form + in forms, and inserts the modified first form into the second form in the same manner, and so on. Useful for expressing pipelines of data." [x & forms] (defn fop [last n] @@ -754,7 +754,7 @@ (defmacro ->> "Threading macro. Inserts x as the last value in the first form - in form, and inserts the modified firsts form into the second form + in forms, and inserts the modified first form into the second form in the same manner, and so on. Useful for expressing pipelines of data." [x & forms] (defn fop [last n] @@ -765,6 +765,38 @@ (tuple/slice parts 0)) (reduce fop x forms)) +(defmacro -?> + "Short circuit threading macro. Inserts x as the last value in the first form + in forms, and inserts the modified first form into the second form + in the same manner, and so on. The pipeline will return nil + if an intermediate value is nil. + Useful for expressing pipelines of data." + [x & forms] + (defn fop [last n] + (def [h t] (if (= :tuple (type n)) + [tuple n.0 (array/slice n 1)] + [tuple n @[]])) + (def sym (gensym)) + (def parts (array/concat @[h sym] t)) + ~(let [,sym ,last] (if ,sym ,(tuple/slice parts 0)))) + (reduce fop x forms)) + +(defmacro -?>> + "Threading macro. Inserts x as the last value in the first form + in forms, and inserts the modified first form into the second form + in the same manner, and so on. The pipeline will return nil + if an intermediate value is nil. + Useful for expressing pipelines of data." + [x & forms] + (defn fop [last n] + (def [h t] (if (= :tuple (type n)) + [tuple n.0 (array/slice n 1)] + [tuple n @[]])) + (def sym (gensym)) + (def parts (array/concat @[h] t @[sym])) + ~(let [,sym ,last] (if ,sym ,(tuple/slice parts 0)))) + (reduce fop x forms)) + (defn partial "Partial function application." [f & more] diff --git a/src/core/fiber.c b/src/core/fiber.c index 31f9b6e3..f8f5e023 100644 --- a/src/core/fiber.c +++ b/src/core/fiber.c @@ -386,7 +386,7 @@ static const JanetReg cfuns[] = { "(fiber/new func [,sigmask])\n\n" "Create a new fiber with function body func. Can optionally " "take a set of signals to block from the current parent fiber " - "when called. The mask is specified as symbol where each character " + "when called. The mask is specified as a symbol where each character " "is used to indicate a signal to block. The default sigmask is :y. " "For example, \n\n" "\t(fiber/new myfun :e123)\n\n"