-
Notifications
You must be signed in to change notification settings - Fork 0
pabloh/ruby-lc
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
ruby-lc is a lazy list comprehension libray, that tries to ressemble Haskell sintax. Rigth now it only works with numbers, (but it may also works with something else that ducktype like a number) For creating a comprehension list just call the CL method with a block, declaring the variables you want to use, as the block's parameters and define the list comprehension expressions inside an Array, like this: CL {|x| [ x , x << (0..10), x % 2 == 0 ]} The call to CL, returns an Enumerator which can be used to access the comprehension list's values. The first element in the Array must always be an expression, the remainder elements may be boolean conditions, or the variable's binding expressions, which uses this sintax: <variable> << <Enumerable>, where << pretends to behave like Haskell's <-. Some examples: LC {|x,y| [x + y, y << (0..20), x << (1..10), y % 7 == 0, x % 2 == 1 ]}.to_a #[1, 3, 5, 7, 9, 8, 10, 12, 14, 16, 15, 17, 19, 21, 23] LC {|x| [x, x << LC::Nat, x > 6, (x % 6 == 1) | (x % 6 == 5) ] }.take 100 #whichs returns the first 100 natural numbers than are congruent 1 or 5 modulo 6, greater than 6. LC {|x| [x ** 2 , x << LC::Nat ,x > 100 , LC.func(:prime?, x) ] }.take 10 #the squares of the first 10 primes numbers above 100 (prime? has to be a 'top-level function')
About
Lazy list comprehension library for ruby
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published