Skip to content

Releases: d0rj/pido

Heavily corrected and slightly expanded version

10 May 16:34
Compare
Choose a tag to compare

Functional

  • Fixed bugs in some cases;
  • Added the ability to automatically output unknown arguments from a lambda function:
# lambda function
(~ {
    dbl <- x * 2
    trpl <- y * 3
    return (dbl + trpl)
})
# is equivalent of
function(x, y) {
    dbl <- x * 2
    trpl <- y * 3
    return (dbl + trpl)
}
  • Added dataframe support for functional stuff;
  • Some bugs fixed;
  • Package warnings fixed.

Minimal working library

18 Apr 13:03
Compare
Choose a tag to compare

Text processing:

  • Porter stemmers for russian and english languages;
  • Simple text tokenization and n-gramms extraction.

Functional features:

New syntax for lambda functions:

Now you can simply write lambda-like function instead of writing build-in keyword function. Example:

c(1, 2, 3, 4, 5) %map% (x ~ x ^ 2)
# Same as
c(1, 2, 3, 4, 5) %map% function(x) { x^2 }
list(c(1, 2, 3, 4, 5), c(5, 4, 3, 2, 1)) %mapN% (x ~ y ~ (x + y) * 2)
# Same as
list(c(1, 2, 3, 4, 5), c(5, 4, 3, 2, 1)) %mapN% function(x, y) { return ((x + y) * 2) }

Also, the syntax allows for some simplifications:

# This line
(x ~ x + 1)
# Same as
(~ x.i + 1)
# Same as
(~ . + 1)

It also support multi-line lambda functions:

(x ~ {
     a <- x + 1
     return (a * 2)
})
# Same as
function(x) {
    a <- x + 1
    return (a * 2)
}

Simple functor

functor(c(1, 2, 3, 4))(function(x) {x * 2})()
# c(1, 4, 9, 16)
functor(c(1, 2, 3, 4))(function(x) {x * 2})(~ . > 4)()
# c(FALSE, FALSE, TRUE, TRUE)

Infix operators for functor (vector):

  • map;
  • mapN;
  • invoke_map;
  • filter;
  • filter_not;
  • head_while;
  • tail_while;
  • any;
  • all;
  • has;
  • flatmap (for monads, but ok);
  • flatten (also for monads).