1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-25 01:37:19 +00:00

Clarify docs on take and drop functions

Pass in indexed and bytes, return tuples and strings, respectively.
This commit is contained in:
John Gabriele 2021-07-24 18:44:49 -04:00 committed by GitHub
parent 160dd830a0
commit 76acbf9bb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1027,7 +1027,7 @@
ret) ret)
(defn take (defn take
"Take first n elements in an indexed type. Returns new indexed instance." "Take the first n elements of an indexed or bytes type. Returns a new tuple or string, respectively."
[n ind] [n ind]
(def use-str (bytes? ind)) (def use-str (bytes? ind))
(def f (if use-str string/slice tuple/slice)) (def f (if use-str string/slice tuple/slice))
@ -1038,7 +1038,7 @@
(f ind 0 end)) (f ind 0 end))
(defn take-until (defn take-until
"Same as (take-while (complement pred) ind)." "Same as `(take-while (complement pred) ind)`."
[pred ind] [pred ind]
(def use-str (bytes? ind)) (def use-str (bytes? ind))
(def f (if use-str string/slice tuple/slice)) (def f (if use-str string/slice tuple/slice))
@ -1048,13 +1048,14 @@
(f ind 0 end)) (f ind 0 end))
(defn take-while (defn take-while
`Given a predicate, take only elements from an indexed type that satisfy `Given a predicate, take only elements from an indexed or bytes type that satisfy
the predicate, and abort on first failure. Returns a new array.` the predicate, and abort on first failure. Returns a new tuple or string, respectively.`
[pred ind] [pred ind]
(take-until (complement pred) ind)) (take-until (complement pred) ind))
(defn drop (defn drop
"Drop first n elements in an indexed type. Returns new indexed instance." ``Drop the first n elements in an indexed or bytes type. Returns a new tuple or string
instance, respectively.``
[n ind] [n ind]
(def use-str (bytes? ind)) (def use-str (bytes? ind))
(def f (if use-str string/slice tuple/slice)) (def f (if use-str string/slice tuple/slice))
@ -1065,7 +1066,7 @@
(f ind start -1)) (f ind start -1))
(defn drop-until (defn drop-until
"Same as (drop-while (complement pred) ind)." "Same as `(drop-while (complement pred) ind)`."
[pred ind] [pred ind]
(def use-str (bytes? ind)) (def use-str (bytes? ind))
(def f (if use-str string/slice tuple/slice)) (def f (if use-str string/slice tuple/slice))
@ -1075,8 +1076,8 @@
(f ind start)) (f ind start))
(defn drop-while (defn drop-while
`Given a predicate, remove elements from an indexed type that satisfy `Given a predicate, remove elements from an indexed or bytes type that satisfy
the predicate, and abort on first failure. Returns a new array.` the predicate, and abort on first failure. Returns a new tuple or string, respectively.`
[pred ind] [pred ind]
(drop-until (complement pred) ind)) (drop-until (complement pred) ind))