Why List partition works while span does not

前端 未结 1 1668
被撕碎了的回忆
被撕碎了的回忆 2021-01-14 06:22

I have this List oX of (Char, Int) pars (it contains pairs with only unique Char values)

List(( ,3), (d,1), (e,3), (h,3), (i,1) , (l,3), (o,2), (r,2), (t,1),         


        
相关标签:
1条回答
  • 2021-01-14 06:59

    From the documentation of span: "Returns the longest prefix of the list whose elements all satisfy the given predicate, and the rest of the list."

    So here span gives you the expected result: since the first tuple in your list doesn't have the character d, the longest prefix of the list where each tuple has the character d is indeed the empty list.

    0 讨论(0)
提交回复
热议问题