Code Monkey home page Code Monkey logo

ava's Introduction

Ava

Ava is a collection of useful utilities in Julia Language that maps closely to the Python counterparts.

For a quick example, in Python, a Counter object can be used to form a bag of words.

>>> words = 'Two roads diverged in a yellow wood'.split()
>>> Counter(words).most_common()

With Ava.Collections you could write something similar:

> import Ava.Strings: Str
> import Ava.Collections: Counter
> words = Str('Two roads diverged in a yellow wood').split()
> Counter(words).most_common()

Examples

Testing a string for alphanumeric:

using Ava
# Do this to avoid namespace clash with `Strings` module.
const Str = Ava.Strings


if !Str.isalpha("10.9")
	println("It's number")
end

List the files in a directory.

> import Ava: Os
> parent = Os.listdir("..")
# listdir has multiple dispatch which defaults empty parameter to "."
> current = Os.listdir()

Case of Module-level Functions

Because Julia is not Object-oriented language, instance methods aren't very idiomatic.

In Python, the conventions were mixed between module-level functions and instance methods. This is a source of confusion for many.

Ava provides convenient wrapper constructors to create an illusion of instance methods. For example:

> using Ava
> const Str = Ava.Strings.Str
> pi = Str("3.1416")
> pi.isalpha()
# false

> Str("Hello, world!").split()
#=
2-element Array{String,1}:
  "Hello,"
  "world!"
=#

Find the ten most common words in Hamlet:

> import Ava.Collections: Counter
> open("hamlet.txt") do f
>	words = matchall(r"\w+", read(f, String))
>	Counter(words).most_common(10)
> end
#=
10-element Array{Pair{Any,Int64},1}:
  "the" => 1143
  "and" => 966
  "to" => 762
   ...
=#

However, module-level functions should be considered better practice.

> import DataStructures: counter
> import Ava.Collections: most_common
> counter(words) |> most_common

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.