Giter Site home page Giter Site logo

ufpb-27a-sdc's Introduction

27a SDC UFPB

Ferramentas:

Libs

Refs


Intro Clojure

History

  • https://clojure.org/about/history

  • Rich Hickey 2007

  • Lisp

  • Functional Programming

  • Hosted JVM (CLR/JS*)

  • Concurrency

  • 2009 (v1.0) / 2022 (v1.11) ~ 12 anos

    • retro compatível (aka Java)
      • o que foi feito em versões mais antigas continua funcionando nas versões mais recentes
    • 1.10.0-alpha5 drops support for Java 6 and 7 and makes Java 8 the minimum requirement. Compilation will produce Java 8 level bytecode (which will not run on earlier versions of Java). This is the first change in bytecode version since Clojure 1.6. (2014)
  • Killer Feature: Data Processing/Transformation

Setup

  • REPL + Setup IDE

    • compilar/avaliar expressões - (ALT + SHIFT + E)
    • compilar/avaliar top form/definicoes/fns (ALT + SHIFT + P)
    • compilar/avaliar todo o ns/load do arquivo para memória (ALT + SHIFT + L)
    • switch do ns para o arquivo corrente do editor (ALT + SHIFT + R)
  • estrutura projeto (lein new)

  • gestão libs/deps

Intro

values & collections

expressions, fn

ns, def, let

flow


Functional Toolkit


Demo

(ns clj-workshop.core
  (:require [clojure.data.json :as json]))

(def url "https://raw.githubusercontent.com/jeffreylancaster/game-of-thrones/master/data/characters.json")

(def content (slurp url))

(keyword "asdfsdaf")
(def characters (:characters (json/read-str content
                                            :key-fn
                                            keyword)))

(count characters)

(take 3 characters)

(reverse (sort (set (map :characterName characters))))

(filter (fn [character]
          (clojure.string/starts-with? character "King"))
        (map :characterName characters))

IMDB scrapper

https://www.imdb.com/chart/top

(ns clj-workshop.imdb
  (:require [net.cgrand.enlive-html :as html]
    [clojure.string :as str])
  (:import (java.net URL)))

(def url (URL. "https://www.imdb.com/chart/top"))

(def content (html/html-resource url))

(def rows (html/select content [:table :tbody.lister-list :tr]))
(defn- get-row-content [row path]
  (-> (html/select row path)
      first
      :content
      first))

(defn movie [row]
  (let [title (get-row-content row [:td.titleColumn :a])
        year (get-row-content row [:td.titleColumn :span.secondaryInfo])
        rating (get-row-content row [:td.ratingColumn :strong])]
    {:title  title
     :year   (Integer/parseInt
               (-> year
                   (str/replace "(" "")
                   (str/replace ")" "")))
     :rating (Double/parseDouble rating)}))

;; Exploring  

(def movies (map movie rows))

(take 10 (reverse (sort-by :rating movies)))

(count movies)

;; Have fun!!!!  
;  
;1. Quais filmes tiveram uma avaliação igual ou superior a 9? 
;  
;2. Quais filmes foram publicados em 2018?  
;  
;3. Quantos filmes do Piratas do Caribe estão na lista?  
;  
;4. Qual o filme mais antigo encontrado na lista?  
;  
;5. Imprima uma tabela formatada da lista de filmes utilizando (see clojure.pprint).

ufpb-27a-sdc's People

Watchers

Lucas Angelino avatar James Cloos avatar

Forkers

luizhengs

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.