MCPcopy Index your code
hub / github.com/clojure/clojure / nthFrom

Method nthFrom

src/jvm/clojure/lang/RT.java:920–953  ·  view source on GitHub ↗
(Object coll, int n)

Source from the content-addressed store, hash-verified

918}
919
920static Object nthFrom(Object coll, int n){
921 if(coll == null)
922 return null;
923 else if(coll instanceof CharSequence)
924 return Character.valueOf(((CharSequence) coll).charAt(n));
925 else if(coll.getClass().isArray())
926 return Reflector.prepRet(coll.getClass().getComponentType(),Array.get(coll, n));
927 else if(coll instanceof RandomAccess)
928 return ((List) coll).get(n);
929 else if(coll instanceof Matcher)
930 return ((Matcher) coll).group(n);
931
932 else if(coll instanceof Map.Entry) {
933 Map.Entry e = (Map.Entry) coll;
934 if(n == 0)
935 return e.getKey();
936 else if(n == 1)
937 return e.getValue();
938 throw new IndexOutOfBoundsException();
939 }
940
941 else if(coll instanceof Sequential) {
942 ISeq seq = RT.seq(coll);
943 coll = null;
944 for(int i = 0; i <= n && seq != null; ++i, seq = seq.next()) {
945 if(i == n)
946 return seq.first();
947 }
948 throw new IndexOutOfBoundsException();
949 }
950 else
951 throw new UnsupportedOperationException(
952 "nth not supported on this type: " + coll.getClass().getSimpleName());
953}
954
955static public Object nth(Object coll, int n, Object notFound){
956 if(coll instanceof Indexed) {

Callers 1

nthMethod · 0.95

Calls 11

prepRetMethod · 0.95
seqMethod · 0.95
nextMethod · 0.95
firstMethod · 0.95
getLengthMethod · 0.80
getMethod · 0.65
lengthMethod · 0.65
valueOfMethod · 0.45
getKeyMethod · 0.45
getValueMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected