Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. package main
  2.  
  3. /**
  4. * Created by ice1000 on 2017/4/27.
  5. *
  6. * @author ice1000
  7. */
  8.  
  9. fun <A, B, C : Any> zipWith(op: (A, B) -> C) = { x: Sequence<A> ->
  10. { y: Sequence<B> ->
  11. val iX = x.iterator()
  12. val iY = y.iterator()
  13. generateSequence {
  14. if (iX.hasNext() and iY.hasNext()) op(iX.next(), iY.next())
  15. else null
  16. }
  17. }
  18. }
  19.  
  20. fun <T : Any> generate() = zipWith { x: Int, y: T -> "[$y * x^$x]" } (
  21. generateSequence(0, Int::inc)
  22. )
  23.  
  24. fun main(args: Array<String>) =
  25. generate<Int>()(sequenceOf(1, 1, 2, 3, 5, 8, 13, 21)).forEach(::println)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement