mirror of
https://github.com/janet-lang/janet
synced 2024-11-25 01:37:19 +00:00
Merge pull request #719 from uvtc/patch-2
Clarify docs on take and drop functions
This commit is contained in:
commit
f6b7cb9c49
@ -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))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user